Linker "undefined reference to" a symbol in CI
The compiler accepted the code, but the linker could not find the definition of a symbol you use. In package builds this usually means a library was not linked, was linked in the wrong order, or a dependency the package provides is missing from the link line.
What this error means
The build reaches the link stage and fails with "undefined reference to 'X'", often for a function from a library you expected the build system to link.
/usr/bin/ld: main.o: in function `main':
main.cc:(.text+0x2a): undefined reference to `SSL_new'
collect2: error: ld returned 1 exit statusCommon causes
A library is not linked
The symbol lives in a library (for example libssl) that is not passed to the linker, so its definition is never found.
Wrong link order between objects and libraries
With static libraries the linker resolves left to right, so a library listed before the object that needs it leaves the symbol unresolved.
How to fix it
Link the providing library after your objects
Add the library and place it after the objects that reference it.
g++ main.o -o app -lssl -lcryptoDeclare the dependency in the build system
In CMake, link the imported target so the flags and order are handled for you.
find_package(OpenSSL REQUIRED)
target_link_libraries(app PRIVATE OpenSSL::SSL OpenSSL::Crypto)How to prevent it
- Link libraries through CMake imported targets so order is correct.
- Install the library dev package so its archive or shared object exists.
- Keep the link line generated by the build system rather than hand-written.