Lars
Lars

Reputation: 9

Compiling error whilst using command from NASM and mingw

I want to play a bit with assembly. To get started I've created a little asm script and tried to compile it. In the first step everything went great:

nasm -felf64 hello.asm

But when I tried to use

ld -o hello.o hello

from MinGW an error occured:

hello.o: file not recognized: File format not recognized

What can I do to fix this problem? I've tried it with gcc as well but then the same error plus one other error occurs.

Upvotes: 1

Views: 337

Answers (1)

xiver77
xiver77

Reputation: 2302

MinGW creates binaries targeting Windows. Windows does not support ELF binaries (or does it? with Windows subsystem for Linux?). Anyway, ld in MinGW will expect that you provide binaries in win64 format not elf64.

nasm -fwin64 hello.asm will most likely work.


No it won't work because I just saw your code, and you are using Linux syscalls under Windows.

Write,

mov rcx, 69
call ExitProcess

instead of,

mov rax, SYS_EXIT
mov rdi, 69
syscall

Leave a comment if it doesn't work.

Upvotes: 3

Related Questions