简体   繁体   中英

Dynamic library using static library in c++ name mangling error

I am trying to create a dynamic(.so) wrapper library along mongoDB c++ driver. There is no problem with the compilation but when I test it in a C++ sample program i get the error

undefined symbol: _ZN5mongo18DBClientConnection15_numConne

which i assume has something to do with name mangling issues.

I compiled the library as

g++ -fPIC -shared mongoquery.cpp -I/pathto/mongodriver -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -o libmongoquery.so

Here's the program I am using for testing:

#include <iostream>
#include <dlfcn.h>
#include "mongoquery.hpp"
using namespace std;

int main()
{
    void *lib_handle;
    int (*fn)(int *,string);
    lib_handle=dlopen("./libmongoquery.so",RTLD_NOW);
    if(!lib_handle)
    {
        cerr<<"Error"<<dlerror();
        return 1;
    }
    fn=(int (*)(int *,string))dlsym(lib_handle,"count_query");
    string q="{}";
    int n;
    (*fn)(&n,q);
    cout<<n;
    dlclose(lib_handle);
return 0;
}

the header mongoquery.hpp contains

#include <iostream>
#include <client/dbclient.h>
#define HOST "localhost"
#define COLLECTION "test.rules"
using namespace mongo;
using namespace std;
class mongoquery
{
    private:
        string q;
        mongo::DBClientConnection c;


    public:
        mongoquery(string);
        int result_count();
};
int count_query(int *,string);

Thanks

The answer can be followed from this question

Dynamic library uses statics libraries, undefined symbols appears

Added for achival purpose

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM