[CDRIVER-3813] CMake project with static OpenSSL does not link Created: 21/Sep/20  Updated: 28/Oct/23  Resolved: 30/Nov/20

Status: Closed
Project: C Driver
Component/s: Build
Affects Version/s: 1.17.2
Fix Version/s: 1.18.0, 1.18.0-alpha

Type: Bug Priority: Major - P3
Reporter: Thomas Jego Assignee: Roberto Sanchez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 20.04
CMake 3.16.0
GCC 9.3.0


Attachments: Text File CMakeLists.txt     File add_mongo.cmake     File main.cpp     File mongocxxdriver.patch    

 Description   

I created a very simple CMake project (see attached files) to test static linkage of OpenSSL but I go the following error message:

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

 

Steps to reproduce:

 

mkdir build
cd build
 
cmake -DBUILD_SHARED_LIBS=OFF -DOPENSSL_USE_STATIC_LIBS=ON ..
 
make -j 6

 

N.B.: If OPENSSL_USE_STATIC_LIBS is unset (or set to OFF), .so are used and compilation works.

 



 Comments   
Comment by Githook User [ 30/Nov/20 ]

Author:

{'name': 'Roberto C. Sánchez', 'email': 'roberto@connexer.com', 'username': 'rcsanchez97'}

Message: CDRIVER-3813 correct linkage when using static OpenSSL
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/2188ce3a674b022fee9b18fb40fabfd68ee159db

Comment by Roberto Sanchez [ 10/Nov/20 ]

thomas.jego@dice-engineering.com, the bug is actually in the C driver, so I have moved the ticket to that project. I am working on implementing a fix.

Comment by Thomas Jego [ 22/Sep/20 ]

Hi kevin.albertson, indeed I'm attempting to link everything statically (C driver and OpenSSL).

C driver and C++ driver are built using the FetchContent feature of CMake. FetchContent feature downloads source code from MongoDB GitHub and builds it directly in my project (see 'add_mongo.cmake' file).

Comment by Kevin Albertson [ 21/Sep/20 ]

Hi thomas.jego@dice-engineering.com, thanks for the report!

I will try to reproduce with the files you included. As a note, the C++ driver does not link to OpenSSL directly, but uses OpenSSL through the C driver. Are you attempting to link both the C driver and OpenSSL statically? If so, it may help to know how you are building/installing the C driver and C++ driver.

Generated at Wed Feb 07 21:19:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.