assembly - MinGW 32 "undefined reference to `ExitProcess@4'" -
for learning purposes wrote small assembler program (test.asm):
global _main extern _exitprocess@4 section .text _main: mov ebx,0 push ebx call _exitprocess@4 than assembled nasm (test.obj):
nasm -f win32 test.asm now trying link "portable executable" (windows 10 32 bit):
ld test.obj but getting error message:
undefined reference `exitprocess@4' as far understand message means, program not linked "kernel32.dll". thought "ld" linking "kernel32.dll" automatically don't have add flags that. if add flag:
ld test.obj -lkernel32 i getting following error message:
cannot find -lkernel32 i sure did dumb mistake maybe can tell me what's wrong.
edit:
if using "gcc" instead work's:
gcc main.obj -nostdlib -lkernel32 so wondering why "gcc" knows "-lkernel32" , "ld" not.
as you've figured out, ld you'll need specify paths find proper libs.
one advice though, if want make life easier on learning process, there exists lightweight linker called golink linking these type of snippets easy doing:
> nasm -f win32 foo.asm && golink foo.obj kernel32.dll golink.exe version 1.0.2.3 - copyright jeremy gordon 2002-2016 - jg@jgnet.co.uk output file: foo.exe format: win32 size: 1,536 bytes it allows link necessary dlls , that's pretty much, don't need mess search paths time.
Comments
Post a Comment