我有一个简单的C语言hello world程序,使用/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 : error LNK2001: 未解析的外部符号 __security_check_cookie@4 asm_test.obj : error LNK2001: 未解析的外部符号 _printf LINK : error LNK2001: 未解析的外部符号 _wmainCRTStartup asm_test.exe : fatal error 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所建议的,我在asm源代码中包含了“INCLUDELIB msvcrt.lib”。程序编译成功并生成可执行文件,但链接器生成了一个警告:
msvcrt.lib(crtmanifestrtm.obj):警告LNK4044:未识别的选项“manifestdependency:type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'”;被忽略
当我启动可执行文件时,C运行时会生成以下错误:
运行时错误:R6034 应用程序尝试不正确地加载 C 运行库