I'm trying to write x86-64 assembly to run on current windows systems (in my case good-old windows 11). I first tried a basic program based on this post:
; ----------------------------------------------------------------------------
; Hello_world.asm
;
; This is a Win64 console program that writes "Hello, World" on one line and
; then exits. It needs to be linked with a C library.
; ----------------------------------------------------------------------------
global _main
extern printf
section .text
_main:
push message
call printf
add esp, 4
ret
message:
db 'Hello, World', 10, 0
When I go to assemble and link I get the following error(s):
nasm -fwin64 Hello_world.asm
gcc Hello_world.obj
Error:
Hello_world.obj:Hello_world.asm:(.text+0x1): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.text'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function `main':
C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:70: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
How do I fix this?