Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to symbol X509_free

Tags:

c++

mongodb

I'm trying to use the mongodb legacy C++ driver. (Here "legacy" means the production version, fwiw.) On an ubuntu 15.04 host using clang++ 3.6 and boost 1.55 (from the ubuntu package repositories) and using mongo-cxx-driver pulled form git, I compiled the driver and then attempted to compile the test program.

$ clang++ -std=c++14 mongo.cc -pthread -lmongoclient -lboost_thread \
  -lboost_system -lboost_regex -lssl -o mo

I see this error:

clang++ -std=c++14 mongo.cc -pthread -lmongoclient -lboost_thread -lboost_system -lboost_regex -lssl -lcrypt -o mo
/usr/bin/ld: /usr/local/lib/libmongoclient.a(ssl_manager.o): undefined reference to symbol 'X509_free@@OPENSSL_1.0.0'
/lib/x86_64-linux-gnu/libcrypto.so.1.0.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Clearly I'm missing X509_free(), but it appears that should be in libssl (which is openSSL1.0.0, says dpkg and the library symlink itself).

Many thanks for any tips.

I don't think it's important here, but this is mongo.cc:

#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h" // for the driver

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
}

int main() {
    mongo::client::initialize();
    try {
        run();
        std::cout << "connected ok" << std::endl;
    } catch( const mongo::DBException &e ) {
        std::cout << "caught " << e.what() << std::endl;
    }
    return EXIT_SUCCESS;
}
like image 868
jma Avatar asked Oct 19 '15 13:10

jma


1 Answers

You should link against libcrypto.so, not libcrypt.so.

like image 150
Nikita Kakuev Avatar answered Nov 13 '22 06:11

Nikita Kakuev