2013-03-26 56 views
2

我下載並提取MASM32 +從以下網站的SDK:使用ML.EXE和LINK.EXE http://www.masm32.com/masmdl.htmMASM32 - 「未解決的外部符號」用下劃線,而鏈接

我然後編譯和鏈接下面的程序:

.386 
.model flat, stdcall 

; Windows libraries 
includelib \masm32\lib\kernel32.lib 
includelib \masm32\lib\user32.lib 
extrn [email protected] : PROC 
extrn [email protected] : 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 [email protected] 
    call [email protected] 

    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 [email protected] 
    test.obj : error LNK2001: unresolved external symbol [email protected] 
    test.exe : fatal error LNK1120: 2 unresolved externals 

嘗試運行在obj文件一個DUMPBIN:(ML.EXE v 6.14)

Dump of file test.obj 
test.obj : warning LNK4048: Invalid format file; ignored 

    Summary 

我覺得奇怪,我說,我無法利用鏈接MASM32的默認功能和文件即裝即用的庫。

+2

如果您使用MASM32,則不需要使用像'extrn MessageBoxA @ 16:PROC' /'call MessageBoxA @ 16'這樣的笨拙語法。你可能已經包含了user32.inc並且完成了調用MessageBoxA NULL,ADDR DisplayText,ADDR ProgramTitle,NULL' – Michael 2013-03-26 06:24:33

回答

2

程序必須使用/ 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和微軟版權聲明之外,鏈接器不提供任何輸出。

注:

ML.EXE 6.14大約是20歲。 (Wikipedia

版本7.0+與Visual C++開發環境捆綁在一起。版本8.0或更高版本是有一定的限制:(masm32.com

「版本7.0及以上的都是微軟的Visual C++ 開發環境的組成部分,並也取得了提供的設備開發工具包的一些 的後續版本Microsoft Windows。版本8.0和更高版本已作爲免費下載從Microsoft提供 根據EULA限制使用免費版本 來開發Microsoft操作系統的代碼。

MASM 8.0可以在這裏找到: http://www.microsoft.com/en-us/download/details.aspx?id=12654

1

EXTRA注意與6.14,

ML.EXE會忽略在這種情況下,/ COFF選項

ml test.asm /c /coff 
(奇怪的問題。)

ml.exe將考慮到/ coff選項。

ml /c /coff test.asm 
+1

也許這是因爲這是語法:'ML [/ options] filelist [/ link linkoptions]' – Daan 2015-09-11 20:58:17