我有一個簡單的hello world C程序並用/ FA編譯它。因此,編譯器也會生成相應的彙編列表。現在我想使用masm/link從生成的.asm列表中組裝可執行文件。編譯通過VC++生成的彙編輸出?
下面的命令行產生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: unresolved external symbol @[email protected] asm_test.obj : error LNK2001: unresolved external symbol _printf LINK : error LNK2001: unresolved external symbol _wmainCRTStartup asm_test.exe : fatal error LNK1120: 3 unresolved externals
這裏是所產生的組件列表
; 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 [email protected][email protected]@[email protected] ; `string'
EXTRN @[email protected]:PROC
EXTRN _printf:PROC
; COMDAT [email protected][email protected]@[email protected]
CONST SEGMENT
[email protected][email protected]@[email protected] 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 [email protected][email protected]@[email protected]
call _printf
add esp, 4
; Line 22
xor eax, eax
; Line 23
ret 0
_wmain ENDP
_TEXT ENDS
END
我正在使用最新的masm32版本(6.14.8444)。
更新:
如所建議的由鈍齒輪,我包括在ASM源的INCLUDELIB msvcrt.lib
。該程序編譯和可執行文件被創建,但鏈接器將生成警告:
msvcrt.lib(crtmanifestrtm.obj) : warning LNK4044: unrecognized option "manifestdependency:type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'"; ignored
當我啓動可執行文件,C運行時生成以下錯誤:
Runtime error: R6034 An application has made an attempt to load the C runtime library incorrectly
您已經提供了庫的路徑,但未列出要鏈接到的任何庫本身。我不確定你需要鏈接到的庫的名稱(因此評論而不是答案)。 – Cogwheel 2010-05-12 23:08:19
也許msvcrt.lib? – Cogwheel 2010-05-12 23:12:08
嗯,它肯定與清單文件有關,但在這一點上我很困難。也許創建一個簡單的普通C++項目,並查看鏈接器設置的線索? – Cogwheel 2010-05-14 15:46:54