2012-02-10 81 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); 

感謝

回答