我有一个简单的 hello world C 程序并用 /FA 编译它。因此,编译器也会生成相应的汇编列表。现在我想使用 masm/link 从生成的 .asm 列表中组装一个可执行文件。
以下命令行产生 3 个链接器错误:
\masm32\bin\ml /I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" /c /coff asm_test.asm
\masm32\bin\link /SUBSYSTEM:CONSOLE /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib" asm_test.obj
表明 C 运行时函数未链接到之前生成的目标文件:
asm_test.obj:错误 LNK2001:未解析的外部符号 @__security_check_cookie@4 asm_test.obj:错误 LNK2001:未解析的外部符号 _printf LINK:错误 LNK2001:未解析的外部符号 _wmainCRTStartup asm_test.exe:致命错误 LNK1120:3 个未解析的外部
这是生成的程序集清单
; Listing generated by Microsoft (R) Optimizing Compiler Version 15.00.30729.01
TITLE c:\asm_test\asm_test\asm_test.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB OLDNAMES
PUBLIC ??_C@_0O@OBPALAEI@hello?5world?$CB?6?$AA@ ; `string'
EXTRN @__security_check_cookie@4:PROC
EXTRN _printf:PROC
; COMDAT ??_C@_0O@OBPALAEI@hello?5world?$CB?6?$AA@
CONST SEGMENT
??_C@_0O@OBPALAEI@hello?5world?$CB?6?$AA@ DB 'hello world!', 0aH, 00H ; `string'
CONST ENDS
PUBLIC _wmain
; Function compile flags: /Ogtpy
; COMDAT _wmain
_TEXT SEGMENT
_argc$ = 8 ; size = 4
_argv$ = 12 ; size = 4
_wmain PROC ; COMDAT
; File c:\users\octon\desktop\asm_test\asm_test\asm_test.cpp
; Line 21
push OFFSET ??_C@_0O@OBPALAEI@hello?5world?$CB?6?$AA@
call _printf
add esp, 4
; Line 22
xor eax, eax
; Line 23
ret 0
_wmain ENDP
_TEXT ENDS
END
我正在使用最新的 masm32 版本(6.14.8444)。
更新:
正如 Cogwheel 所建议的,我INCLUDELIB msvcrt.lib
在 asm 源代码中包含了一个。程序编译并创建了一个可执行文件,但链接器会生成一个警告:
msvcrt。忽略
当我启动可执行文件时,C 运行时会生成以下错误:
运行时错误:R6034 应用程序尝试错误地加载 C 运行时库