2

我从以下网站下载并提取了 MASM32 + SDK:http: //www.masm32.com/masmdl.htm

然后我使用 ml.exe 和 link.exe 编译并链接了以下程序:

.386
.model flat, stdcall

; Windows libraries
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
extrn MessageBoxA@16 : PROC
extrn ExitProcess@4 : PROC

option casemap:none ; Treat labels as case-sensitive

.DATA           ; Begin initialized data segment
  ProgramTitle db "Hello, puny humans!", 0 ; define byte
  DisplayText db "Wahahaha", 0

.CODE           ; Begin code segment
_main PROC

  push 0
  mov eax, offset ProgramTitle
  push eax
  push offset DisplayText
  push 0

  call MessageBoxA@16
  call ExitProcess@4

  ret
_main ENDP

END 

命令行:

ml /c test.asm
link /entry:_main /subsystem:windows test.obj

输出:

ml /c test.asm
    Assembling:  test.asm

link /entry:_main /subsystem:windows test.obj    
    test.obj : warning LNK4033: converting object format from OMF to COFF
    test.obj : error LNK2001: unresolved external symbol _MessageBoxA@16
    test.obj : error LNK2001: unresolved external symbol _ExitProcess@4
    test.exe : fatal error LNK1120: 2 unresolved externals

尝试在 .obj 文件上运行垃圾箱:

Dump of file test.obj
test.obj : warning LNK4048: Invalid format file; ignored

    Summary

我无法使用 MASM32 (ml.exe v. 6.14) 的默认功能和开箱即用的库来链接文件,这对我来说似乎很奇怪。

4

2 回答 2

3

该程序必须使用 /coff 选项进行编译。ml 6.14 默认为 OMF。这是 dumpbin 拒绝文件(它只接受 COFF)和链接器警告“将对象格式从 OMF 转换为 COFF”的原因:

ml /c /coff test.asm

dumpbin 输出反映了这一点:

File Type: COFF OBJECT

    Summary

        1D .data
        48 .drectve
        1A .text

除了 test.exe 和 Microsoft 的版权声明之外,链接器没有任何输出。

笔记:

ML.EXE 6.14 大约有 20 年的历史。(维基百科

7.0+ 版与 Visual C++ 开发环境捆绑在一起。8.0+ 版本受到某些限制:( masm32.com )

“7.0 版及更高版本是 Microsoft Visual C++ 开发环境的组件,并且已在许多用于 Microsoft Windows 后续版本的设备开发套件中提供。8.0 版及更高版本已根据最终用户许可协议从 Microsoft 免费下载,将免费版本的使用限制为为 Microsoft 操作系统开发代码。”

MASM 8.0 可在此处获得:http: //www.microsoft.com/en-us/download/details.aspx?id=12654

于 2013-03-26T02:08:58.173 回答
0

6.14 的额外说明

在这种情况下,ml.exe 将忽略 /coff 选项(奇怪的问题。)

ml test.asm /c /coff

ml.exe 将考虑 /coff 选项。

ml /c /coff test.asm
于 2014-05-19T22:25:56.910 回答