2012-02-10 57 views
0

我正在尝试沿着mongoDB C++驱动程序创建一个动态(.so)包装库。没有与编译没有问题,但是当我在C++示例程序测试我的错误动态库在C++名称中使用静态库mangling error

undefined symbol: _ZN5mongo18DBClientConnection15_numConne 

我假设有事情做与名字改编的问题。

我编译库作为

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

下面是我使用的测试程序:

#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; 
} 

头mongoquery.hpp包含

#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); 

感谢

回答