如何使用nasm和alink组合链接kernel32.lib和user32.lib
我正在学习一些关于程序集编程的教程,指南希望我执行以下命令:
nasm -fobj hello.asm
alink -oPE hello \lib\kernel32.lib \lib\user32.lib第一个命令按预期执行,但是第二个命令失败。
为了链接.lib文件,我从
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib进入我现在的文件夹。
执行第二个命令时收到的错误消息是:
Loading file hello.obj
Loading file Kernel32.lib
2327 symbols
Loaded first linker member
Loading file User32.lib
1385 symbols
Loaded first linker member
matched Externs
matched ComDefs
Unresolved external MessageBoxA
Unresolved external ExitProcess现在,我有两个问题:
1)内核32.lib和user32.lib位于哪里?
2)如何正确链接这些库文件?
操作系统是Windows 10 (64位).
更新:
; Coded for NASM ;
; nasm -fobj hello.asm ;
; alink -oPE hello \lib\kernel32.lib \lib\user32.lib ;
;
extern MessageBoxA ; APIs used ;
extern ExitProcess ; in this file ;
;
[SECTION CODE USE32 CLASS=CODE] ; code section ;
..start: ; for the linker ;
;
push byte 0 ; only the buttons 'OK' ;
push dword caption ; caption of the BOX ;
push dword text ; text in the BOX ;
push byte 0 ; handle of the Box ;
call MessageBoxA ; print BOX on screen ;
;
push byte 0 ; ;
call ExitProcess ; EXIT ;
;
caption db "Your first WIN32 programm",0 ;
text db "HELLO",0 ;
;
end ; for the linker发布于 2017-04-22 05:44:34
我找到了一个kernel.lib或user.lib,可以供ALINK使用。这可能是由于所需的.obj文件的格式,而大多数Windows.obj的格式都是在COFF ALINK中格式化的。
合适的WIN32.LIB是这里。它包括MessageBoxA,但不包括ExitProcess。不建议使用简单的RET来终止纯Windows程序。
然而,NASM如果不是更好的话,也可以做得更好:
; Import the needed Win32 API functions.- http://www.nasm.us/doc/nasmdoc7.html#section-7.4.4
IMPORT ExitProcess kernel32.dll
IMPORT MessageBoxA user32.dll
; Still needed to be declared as external
EXTERN ExitProcess, MessageBoxA
[SECTION CODE USE32 CLASS=CODE] ; code section
..start:
push 0 ; only the buttons 'OK'
push dword caption ; caption of the BOX
push dword text ; text in the BOX
push 0 ; handle of the Box
call [MessageBoxA] ; print BOX on screen
push 0
call [ExitProcess]
caption db "Your first WIN32 programm",0
text db "HELLO",0请注意,函数在调用时使用括号进行修饰。此外,最好将变量放在单独的数据部分中。
如果您计划使用一堆从..DLL的tahe导入的大型项目,请看一下NASMX项目。
https://stackoverflow.com/questions/38222139
复制相似问题