【发布时间】:2016-11-08 09:28:37
【问题描述】:
如何使用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) kernel32.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
【问题讨论】:
-
您正在从正确的文件夹中获取 LIB 文件,但您确实不应该将它们复制到其他地方。只需为链接器提供路径,以便它可以找到它们。否则,我猜你的问题是 ALINK 不支持生成 64 位可执行文件。您需要生成 32 位目标代码,或者使用不同的链接器。
-
您编译/链接 32 位或 64 位代码?以及如何在 asm 文件中声明 MessageBoxA 和 ExitProcess ?
-
我的目的是编译/链接 32 位代码。我在上面添加了完整的示例。
标签: windows winapi assembly windows-10 nasm