我正在尝试仅使用 masm 而不是 masm32 库创建一个 helloworld 程序。这是代码片段:
.386
.model flat, stdcall
option casemap :none
extrn MessageBox : PROC
extrn ExitProcess : PROC
.data
HelloWorld db "Hello There!", 0
.code
start:
lea eax, HelloWorld
mov ebx, 0
push ebx
push eax
push eax
push ebx
call MessageBox
push ebx
call ExitProcess
end start
我可以使用 masm 组装它:
c:\masm32\code>ml /c /coff demo.asm
Microsoft (R) Macro Assembler Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: demo.asm
但是,我无法链接它:
c:\masm32\code>link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user
32.lib demo.obj
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
demo.obj : error LNK2001: unresolved external symbol _MessageBox
demo.obj : error LNK2001: unresolved external symbol _ExitProcess
demo.exe : fatal error LNK1120: 2 unresolved externals
我在链接期间包含了库,所以不知道为什么它仍然显示未解析的符号?
更新:
c:\masm32\code>link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user
32.lib demo.obj
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.
demo.obj : error LNK2001: unresolved external symbol _MessageBox@16
demo.exe : fatal error LNK1120: 1 unresolved externals
更新 2:最终工作代码!
.386
.model flat, stdcall
option casemap :none
extrn MessageBoxA@16 : PROC
extrn ExitProcess@4 : PROC
.data
HelloWorld db "Hello There!", 0
.code
start:
lea eax, HelloWorld
mov ebx, 0
push ebx
push eax
push eax
push ebx
call MessageBoxA@16
push ebx
call ExitProcess@4
end start