ld "DSO missing from command line" in CI
A symbol is satisfied only by a shared library pulled in indirectly. With --as-needed (the modern default) the linker requires that library to be named explicitly on the link line.
What this error means
An undefined reference is followed by a hint that the defining DSO is missing from the command line, usually for a transitive dependency.
ld
/usr/bin/ld: main.o: undefined reference to 'BZ2_bzBuffToBuffCompress'
/usr/bin/ld: note: 'BZ2_...' is defined in DSO /usr/lib/libbz2.so so try adding it to the linker command line
/usr/bin/ld: libbz2.so: could not read symbols: DSO missing from command lineCommon causes
How to fix it
List the library explicitly
- Add the named DSO to the link line, after the objects that use it.
- In CMake, add it to target_link_libraries for the target.
ld
gcc main.o -o app -lbz2 # name the transitive dependency directlyHow to prevent it
- Link directly against every library whose symbols you use, rather than relying on transitive linkage under --as-needed.
Related guides
ld "undefined reference to 'X'" in CIFix ld "undefined reference to 'X'" in CI - the linker found a declaration but no definition, usually a missi…
ld "undefined reference to pthread_create" (missing -pthread) in CIFix ld "undefined reference to pthread_create" in CI - threading code linked without -pthread, so the POSIX t…