Use ld on a 64 bit platform to create a 32 bit executable

I wrote an assembly that builds with:

$as --32 -o hello.o hello.s

      

Then I tried to generate an executable with:

$ld -o hello hello.o

      

This gives me an error:

ld: i386 architecture of input file `ConditionalBranching.o' is incompatible with i386:x86-64 output

      

I tried using the -m32 or -32 flag, but ld doesn't take them. I cannot find a solution by reading the ld man page. How can I generate a 32 bit binary from my 32 bit shared object?

+3


source to share


1 answer


Your linker is trying to create a 64-bit binary, but your assembly code was built for a 32-bit architecture. This creates a mismatch.



Fix this by passing a flag to -m elf_i386

your linker, explicitly telling it to create a 32-bit binary.

0


source







All Articles