Vinculando ao Kernel32.lib no montador
Comecei a aprender assembly hoje e fiz muitos testes no linux que funcionaram muito bem! Eu mudei para o meu PC e comecei a tentar escrever alguns aqui. Eu corri para um problema ao tentar chamar funções externas (que, novamente, funcionou bem no linux) onde eu iria ficar LINK 2001 Unresolved External erros dizendo-me que WriteConsoleA não está definido quando depois de compilar com nasm:
nasm -f win32 test.asm -o test.obj
e com cl.exe:
cl test.obj /link libcmt.lib kernel32.lib
Eu recebo esses erros:
test.obj : error LNK2001: unresolved external symbol ExitProcess
test.obj : error LNK2001: unresolved external symbol GetStdHandle
test.obj : error LNK2001: unresolved external symbol WriteConsoleA
test.exe : fatal error LNK1120: 3 unresolved externals
A montagem:
extern ExitProcess, GetStdHandle, WriteConsoleA
NULL equ 0
STD_OUTPUT_HANDLE equ -11
section .data
msg db "Hello world!",0xa
msgLen equ $-msg
section .bss
dummy resd 1
section .text
global _main
_main:
push STD_OUTPUT_HANDLE
call GetStdHandle
push NULL
push dummy
push msgLen
push msg
push eax
call WriteConsoleA
push NULL
call ExitProcess
Copiado quase exatamente deAqui. Qualquer ajuda é muito apreciada! Obrigado!