Skip to content
Latchkey

ld "cannot find -lX" in CI

The linker was asked for -lX but found no libX.so or libX.a in any search directory. The development package is missing or the library is in a non-standard path.

What this error means

Linking fails with "cannot find -lfoo", typically because the -dev package is absent on the CI image.

ld
/usr/bin/ld: cannot find -lpng: No such file or directory
collect2: error: ld returned 1 exit status

Common causes

How to fix it

Install the library or add -L

  1. Install the development package that ships lib<X>.so.
  2. Add -L<dir> for libraries in a custom prefix.
ld
apt-get install -y libpng-dev
gcc app.o -o app -L/opt/png/lib -lpng

How to prevent it

  • Install all -dev library packages in the runner image and pass -L for any library outside the standard directories.

Related guides

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