【问题标题】:MASM32 - "Unresolved external symbols" with underscores while linkingMASM32 - 链接时带有下划线的“未解析的外部符号”
【发布时间】:2013-03-26 02:08:58
【问题描述】:

我从以下网站下载并提取了 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) 的默认功能和开箱即用的库链接文件,这对我来说似乎很奇怪。

【问题讨论】:

  • 如果您使用 MASM32,则无需使用像 extrn MessageBoxA@16 : PROC / call MessageBoxA@16 这样的笨拙语法。您可以只包含 user32.inc 并完成 invoke MessageBoxA NULL,ADDR DisplayText,ADDR ProgramTitle,NULL

标签: windows assembly masm32


【解决方案1】:

必须使用 /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 年的历史。 (Wikipedia)

7.0+ 版与 Visual C++ 开发环境捆绑在一起。 8.0+ 版本有一定的限制:(masm32.com)

“7.0 及更高版本是 Microsoft Visual C++ 的组件 开发环境,并且还提供了一些 用于 Microsoft 后续版本的设备开发工具包 视窗。 8.0 版及更高版本可免费下载 根据限制免费版本使用的 EULA 来自 Microsoft 为 Microsoft 操作系统开发代码。”

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

【讨论】:

    【解决方案2】:

    额外说明与 6.14,

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

    ml test.asm /c /coff
    

    ml.exe 将考虑 /coff 选项。

    ml /c /coff test.asm
    

    【讨论】:

    • 可能是因为语法是这样的:ML[ /options ] filelist [ /link linkoptions ]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多