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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →