ld "skipping incompatible libX.so when searching for -lX" in CI
ld skips libraries whose architecture or ABI does not match the link target. It prints "skipping incompatible ..." for each one, then fails with "cannot find -lX" if no matching library remains.
What this error means
A link finds a library but rejects it as incompatible, usually a 32-bit library in a 64-bit build or a cross build pointed at host libraries.
ld
/usr/bin/ld: skipping incompatible /usr/lib/i386-linux-gnu/libz.so
when searching for -lz
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit statusCommon causes
How to fix it
Install the matching architecture library
- Install the library built for the architecture you are linking.
- Or point -L at the directory holding the correct-architecture build.
Terminal
# for a 64-bit build, install the 64-bit dev package
apt-get install -y zlib1g-dev
gcc main.o -o app -lzSearch the target sysroot when cross compiling
Pass --sysroot so ld searches the target tree rather than incompatible host libraries.
Terminal
aarch64-linux-gnu-gcc --sysroot=/opt/sysroot main.o -o app -lzHow to prevent it
- Keep library architecture consistent with the link target and use a target sysroot for cross builds so ld never has to skip incompatible libraries.
Related guides
ld "cannot find crtbeginS.o / crt1.o" in CIFix ld "cannot find crtbeginS.o" or "cannot find crt1.o" in CI - the C runtime startup objects are missing be…
ld "warning: libX.so, needed by ..., not found" in CIFix ld "warning: libX.so.N, needed by Y, not found (try using -rpath ...)" in CI - a dependency of a library…