linuxassemblyx86nasmcross-compiling

helloWorld.o: file not recognized: File format not recognized (cross-assembling a Linux executable on Windows)


I assembled an assembly file called "helloWorld.s" and saved it into "helloWorld.o" and then I tried to link it but it gave me this error "helloWorld.o: file not recognized: File format not recognized", I wonder why is that?

I used NASM Assembler.

Here are the commands I wrote:

C:\>nasm -f elf64 helloWorld.s

C:\>ld -o helloWorld helloWorld.o
helloWorld.o: file not recognized: File format not recognized

Note:

The Executable for linux OS but I just trying to essemble it and link it on Windows OS and the will transfer it.


Solution

  • Creating a Linux executable on Windows using the ld linker is not a straightforward process because ld on Windows typically produces Windows-compatible executables (PE format), not Linux-compatible executables (ELF format). However, you can use a cross-compiler toolchain on Windows to achieve your goal.