DSO missing from command line (With CMake)

Rikky picture Rikky · Oct 16, 2016 · Viewed 16k times · Source

I am trying to convert a c++ project from Windows to Debian by compiling everything again with Cmake.

I am not really use to work on Linux but I have managed to install everything properly.

This is the error:

/usr/bin/ld: ../shared/libshared.a(BigNumber.cpp.o): undefined reference to symbol 'BN_new@@OPENSSL_1.0.2d'

//usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2: error adding symbols: DSO missing from command line

This actually seems like a common question but I don't know what to do with Cmake. I already saw few answers like:

DSO missing from command line

How do I tell CMake to link in a static library in the source directory?

How to add linker or compile flag in cmake file?

I am a bit confused, could you help me to understand what I need to do with Cmake please?

Thank you

Answer

squareskittles picture squareskittles · Aug 22, 2020

It is hard to guess what may be going wrong without seeing the CMake file itself, but here are some possible solutions.

Based on the similar error in your first referenced answer (DSO missing from command line), it would seem you may have simply forgotten to link to the libcrypto.so.1.0.2 library (or perhaps missed the ssl library as well). In my experience, these are often used in tandem, so linking both may be what you need. Use the target_link_libraries command to link these libraries to your CMake target:

target_link_libraries(MyLib PRIVATE ssl crypto)

I've also seen cases where this error arises due to a mismatch in the OpenSSL versions. For example, OpenSSL version 1.1 may be installed on your machine, but the library or packages you are using require version 1.0.2 (as the error suggests). If this is the case, you can uninstall the current OpenSSL version (1.1) and install the older version (1.0.2):

apt-get purge libssl-dev
apt-get install libssl1.0-dev