Skip to content
Latchkey

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 status

Common causes

How to fix it

Install the matching architecture library

  1. Install the library built for the architecture you are linking.
  2. 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 -lz

Search 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 -lz

How 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.

Frequently asked questions

What causes ""skipping incompatible""?
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.
How do I fix "skipping incompatible"?
Install the matching architecture library

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card