簡體   English   中英

盡管鏈接了庫,但我的x86-32代碼中未解析的外部符號

[英]Unresolved external symbols in my x86-32 code despite linking the library

我正在用Microsoft的技巧學習x86,並且嘗試調用ExitProcess。 我知道此函數是在kernel32.lib中定義的,因此我在構建步驟中將其鏈接了,無法正常工作。 我嘗試在源代碼中執行“ includelib kernel32.lib”,同樣的錯誤。 這是我用來構建它的代碼和命令:

.model flat, C
.stack 4096

includelib kernel32.lib
includelib user32.lib

extrn ExitProcess: proc

.code
main proc
    mov eax, 0
    ret
main endp

end main

這就是我構建此源代碼的方式(我正在使用命令行工具ml.exe):

ml -Zi -nologo ..\code\main.asm /link -nologo -subsystem:windows User32.lib Kernel32.lib -entry:main

這是匯編器拋出的錯誤:

Assembling: ..\code\main.asm
main.obj : error LNK2019: unresolved external symbol _ExitProcess referenced in function _main

main.exe:致命錯誤LNK1120:1個未解決的外部組件我已經在網上進行了廣泛的搜索,但這似乎是匯編我的代碼所需的全部。 我只是不知道如何使它工作。 請幫忙。

如果您不喜歡導出函數的怪異且丑陋的名稱處理,那么您並不孤單。 我認為函數應使用與記錄中相同的名稱進行調用,例如在https://docs.microsoft.com/zh-cn/windows/desktop/api/winuser/nf-winuser-messagebox中

我寫了一個工具https://euroassembler.eu/ ,它比MASM易於使用。 您在EUROASM中的程序如下所示:

main program format=PE,entry=main
      import MessageBoxA,lib=user32.dll
      import ExitProcess,lib=kernel32.dll
 main proc
       push 0, ="Caption", ="Hello, world!",0 ; Msgbox requires 4 parameters.
       call MessageBoxA
       push 0                                 ; ExitProcess requires 1 parameter.
       call ExitProcess
      endp
    endprogram

這是我從此源構建main.exe的方法:

euroasm.exe main.asm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM