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

27,428

Solution 1

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

Solution 2

nasm -f elf64 array1.asm

then

ld -s -o array1 array1.o

Solution 3

First install this:

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

then Assemeble and link in this way:

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

And finaly,

gcc -m32 array1.o -o array1.out

and run,

./array1.out

This should work......

Solution 4

(oops, I only skimmed the question, and thought you were making a standalone executable with just ld. See cad's answer for gcc -m32, for when you do want to link with libc and all that, rather than just try some little experiment as a standalone.)

You have to tell ld what machine you want the output to be for. It defaults to the native type.

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

Unfortunately, a lot of asm guides / resources still have examples with 32bit x86 code.

Share:
27,428
beegee Assem
Author by

beegee Assem

Getting nostalgic about stuff... planning to relearn

Updated on December 19, 2020

Comments

  • beegee Assem
    beegee Assem over 3 years

    I am using Kali linux 64 bit and I am trying to execute the following programs from Dr. Paul carter's website. The gcc command is giving errors. What should I use in the 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