对符号X509_free的未定义引用

Undefined reference to symbol X509_free

本文关键字:未定义 引用 free 符号 X509      更新时间:2023-10-16

我试图使用mongodb遗留的c++驱动程序。(这里的"遗留"是指生产版本。)在ubuntu 15.04主机上,使用clang++ 3.6和boost 1.55(来自ubuntu软件包库),并使用从git中提取的mongo-cxx-driver,我编译了驱动程序,然后尝试编译测试程序。

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

看到这个错误:

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)

显然我遗漏了X509_free(),但它似乎应该在libssl(这是openSSL1.0.0,说dpkg和库符号链接本身)。

非常感谢你的建议。

我不认为这是重要的,但这是蒙古。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;
}

你应该链接libcrypto.so,而不是libcrypt.so