Could not compile assembly: / usr / bin / ld: i386 architecture of input file `array1.o 'is incompatible with i386: x86-64 output

I am using the 64-bit version of Kali linux and I am trying to run the following programs on the Dr. website Paul Carter. The gcc command gives errors. What should i use in gcc command?

nasm -f elf32 array1.asm root@kali :assembly# gcc -o array1 array1.o array1c.c array1c.c:9:1: warning: 'cdecl' attribute ignored [-Wattributes] array1c.c:10:1: warning: 'cdecl' attribute ignored [-Wattributes] /usr/bin/ld: i386 architecture of input file `array1.o' is incompatible with i386:x86-64 output collect2: error: ld returned 1 exit status 
+5
source share
4 answers

You are trying to link a 32-bit i386 object file with a 64-bit executable file ( i386:x86-64 ). Add -m32 to the gcc compilation line to create a 32-bit executable.

+5
source

First install this:

 sudo apt-get install gcc-multilib g++-multilib 

then Assemeble and the link as follows:

 nasm -f elf array1.asm -o array1.o 

And finally

 gcc -m32 array1.o -o array1.out 

and run

 ./array1.out 

That should work ...

+2
source
 nasm -f elf64 array1.asm 

then

 ld -s -o array1 array1.o 
+2
source

(oops, I just looked at the question and thought that you are making a standalone executable with only ld . See the cad answer for gcc -m32 , because when you want to connect to libc and all this, and not just try a little experiment as standalone .)

You must tell ld which machine you want to work on. By default, a native type is used.

 nasm -f elf32 array1.asm # or yasm ld -m elf_i386 array1.o -o 32bit-array1 

Unfortunately, most asm manuals / resources still have examples with 32-bit x86 code.

+1
source

All Articles