Search code examples
gccld

Skipping incompatible directory - gcc


I am trying to compile a script using some libraries available in a package using:

gcc -g -o sac2mt5 sac2mt5.o libsac2mt5.a -L/home/yuki/sac/lib -lsacio -lm

This is the error I am getting:

/usr/bin/ld: skipping incompatible /home/yuki/sac/lib/libsacio.a when searching for -lsacio
/usr/bin/ld: cannot find -lsacio
collect2: error: ld returned 1 exit status

What is the problem here? Why is this library incompatible? What needs to be changed in the flags to avoid this? I just want to know if this is a problem with the library, which then, I can't do anything about, or whether I am doing something wrong.

Any help is apreciated


Solution

  • The library /home/yuki/sac/lib/libsacio.a was built for an architecture incompatible with the one for which you are attempting to link the program. The likeliest cause is that the library contains 32-bit object files and you are attempting a 64-bit linkage. The next likeliest is a 64-bit library in a 32-bit linkage.

    If you cd to the directory where you ran this linkage and run:

    $ objdump -f sac2mt5.o
    

    the output will contain lines of the form:

    sac2mt5.o:  file format <...>
    architecture: <...>, flags 0x<...>:
    

    e.g. (64-bit ELF):

    sac2mt5.o:     file format elf64-x86-64
    architecture: i386:x86-64, flags 0x00000010:
    

    or (32-bit ELF):

    sac2mt5.o:     file format elf32-i386
    architecture: i386, flags 0x00000010:
    

    These tell you the name of the architecture you trying to link for (the architecture of your system) and the name of its object file format.

    If you then also run:

    $ objdump -f /home/yuki/sac/lib/libsacio.a
    

    you will see the corresponding information for each object file in the archive /home/yuki/sac/lib/libsacio.a, and you will see that the architecture and file format of those object files does not match your system.

    You need to find and use a libsacio.a that was built for the same architecture as your system - most likely a 64-bit library if your system is 64-bit; a 32-bit library if your system is 32-bit.