如何解决Nasm-Crinkler无法导入winapi函数
我一直试图将codeproject program与Nasm和Crinkler组合在一起,但是每次我尝试将目标文件与kernel32.lib和user32.lib链接时,都会给我以下输出:
Crinkler 2.3 (Jul 21 2020) (c) 2005-2020 Aske Simon Christensen & Rune Stubbe
Target: out.exe
Tiny compressor: YES
Tiny import: NO
Subsystem type: WINDOWS
Large address aware: NO
Compression mode: SLOW
Saturate counters: NO
Hash size: 500 MB
Hash tries: 100
Order tries: 0
Reuse mode: OFF (no file specified)
Report: NONE
Transforms: NONE
Replace DLLs: NONE
Fallback DLLs: NONE
Range DLLs: NONE
Exports: NONE
Loading window.obj...
Loading kernel32.lib...
Loading user32.lib...
Linking...
Forced alignment of 1 code hunk to 1 (including entry point).
WINDOW.OBJ: START: error LNK: Cannot find symbol 'GetModuleHandleA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'LoadIconA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'LoadCursorA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'RegisterClassExA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'MessageBoxA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'CreateWindowExA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'ShowWindow'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'UpdateWindow'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'PeekMessageA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'TranslateMessage'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'DispatchMessageA'
WINDOW.OBJ: START: error LNK: Cannot find symbol 'ExitProcess'
WINDOW.OBJ: WindowProc: error LNK: Cannot find symbol 'PostQuitMessage'
WINDOW.OBJ: WindowProc: error LNK: Cannot find symbol 'DefWindowProcA'
我还尝试将其与golink链接,并且在格式上也给了我同样的错误:
GoLink.Exe Version 1.0.3.0 Copyright Jeremy Gordon 2002-2018 info@goprog.com
Error!
The following symbols were not defined in the object file or files:-
ExitProcess
RegisterClassExA
CreateWindowExA
MessageBoxA
GetModuleHandleA
PeekMessageA
TranslateMessage
DispatchMessageA
PostQuitMessage
DefWindowProcA
ShowWindow
UpdateWindow
LoadIconA
LoadCursorA
Output file not made
命令行为:
nasm window.asm -f win32
crinkler /NODEFAULTLIB /ENTRY:START /SUBSYSTEM:WINDOWS /TINYHEADER window.obj kernel32.lib user32.lib
golink window.obj kernel32.lib user32.lib
在代码中,我有:
extern printf
extern ExitProcess
;all other externs
;more code
START:
push 0
call GetModuleHandleA
;more code
当我删除链接器上的kernel32.lib和user32.lib时,我注意到了另一个奇怪的事情,我得到了新的错误:
Crinkler import: _Import: error LNK: Cannot find symbol '__imp__MessageBoxA@16'
Crinkler import: _Import: error LNK: Cannot find symbol '__imp__LoadLibraryA@4'
我通常期望失败的导入,通常它们的名称前有“ imp ”,其后有“ @number”。
此外,我尝试导入win32n.inc并使用:
import ExitProcess kernel32.dll
以nasm输出失败:
error: parser: instruction expected
关于它为什么发生以及如何解决的任何想法? 谢谢。
解决方法
解决了!
只需将每个extern "name"
替换为我必须通过查看kernel32.lib和user32.lib而获得的extern _"name"@"number"
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。