2015-11-06 44 views
0

當我開始使用clang編譯代碼時,似乎libmongoclient不存在。但是,我在這臺Ubuntu機器上編譯了mongo-cxx-client的舊版本。此代碼在我的Mac上正常工作。與C++中的libmongoclient鏈接時出錯

clang -lstdc++ -stdlib=libc++ -lcurl -lpthread -ljsoncpp -lboost_system -lboost_regex -lmongoclient -L/usr/lib main.o qqlogin.o fetcher.o -o qq_crawler 

這是鏈接的代碼。沒有參數-lmongoclient沒有任何區別。我已經確認它是在正確的路徑下並且編譯能夠搜索它。

main.o: In function `main': 
main.cpp:(.text+0x3b): undefined reference to `mongo::client::Options::Options()' 
main.cpp:(.text+0x4b): undefined reference to `mongo::client::GlobalInstance::GlobalInstance(mongo::client::Options const&)' 
main.cpp:(.text+0x2d4): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()' 
main.cpp:(.text+0x310): undefined reference to `mongo::client::GlobalInstance::~GlobalInstance()' 
main.o: In function `thread_main(threadtool::Threadsafe_queue<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*)': 
main.cpp:(.text+0x343): undefined reference to `mongo::DBClientConnection::DBClientConnection(bool, mongo::DBClientReplicaSet*, double)' 
main.o: In function `GCC_except_table14': 
main.cpp:(.gcc_except_table+0x258): undefined reference to `typeinfo for mongo::DBException' 
main.o: In function `mongo::DBClientConnection::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)': 
main.cpp:(.text._ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo18DBClientConnection7connectERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x116): undefined reference to `mongo::HostAndPort::HostAndPort(mongo::StringData const&)' 
main.o: In function `mongo::DBClientConnection::~DBClientConnection()': 
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x12): undefined reference to `vtable for mongo::DBClientConnection' 
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x1d): undefined reference to `vtable for mongo::DBClientConnection' 
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x22): undefined reference to `mongo::DBClientConnection::_numConnections' 
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0xc4): undefined reference to `mongo::DBClientBase::~DBClientBase()' 
main.cpp:(.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD2Ev]+0x15d): undefined reference to `mongo::DBClientBase::~DBClientBase()' 
main.o: In function `mongo::DBException::~DBException()': 
main.cpp:(.text._ZN5mongo11DBExceptionD2Ev[_ZN5mongo11DBExceptionD2Ev]+0xc): undefined reference to `vtable for mongo::DBException' 
main.o: In function `mongo::UserException::UserException(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)': 
main.cpp:(.text._ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo13UserExceptionC2EiRKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x30): undefined reference to `vtable for mongo::UserException' 
main.o: In function `mongo::DBException::addContext(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)': 
main.cpp:(.text._ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE[_ZN5mongo11DBException10addContextERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE]+0x51): undefined reference to `mongo::causedBy(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)' 
main.o: In function `mongo::DBException::DBException(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)': 
main.cpp:(.text._ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi[_ZN5mongo11DBExceptionC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEi]+0xf): undefined reference to `vtable for mongo::DBException' 
main.o:(.rodata._ZTIN5mongo16ConnectExceptionE[_ZTIN5mongo16ConnectExceptionE]+0x10): undefined reference to `typeinfo for mongo::UserException' 
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x30): undefined reference to `mongo::UserException::appendPrefix(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const' 
main.o:(.rodata._ZTVN5mongo16ConnectExceptionE[_ZTVN5mongo16ConnectExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const' 
main.o:(.rodata._ZTVN5mongo18AssertionExceptionE[_ZTVN5mongo18AssertionExceptionE]+0x40): undefined reference to `mongo::DBException::toString() const' 
main.o:(.rodata._ZTIN5mongo18AssertionExceptionE[_ZTIN5mongo18AssertionExceptionE]+0x10): undefined reference to `typeinfo for mongo::DBException' 
fetcher.o: In function `fetch::Fetcher::parsed_json(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&)': 
fetcher.cpp:(.text+0x1e8c): undefined reference to `Json::Reader::parse(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Json::Value&, bool)' 
fetcher.o: In function `mongo::BSONObjBuilder::BSONObjBuilder(int)': 
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilderC2Ei[_ZN5mongo14BSONObjBuilderC2Ei]+0x4e): undefined reference to `mongo::BSONObjBuilderValueStream::BSONObjBuilderValueStream(mongo::BSONObjBuilder*)' 
fetcher.o: In function `mongo::BSONObjBuilder::append(mongo::StringData const&, mongo::Date_t)': 
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE[_ZN5mongo14BSONObjBuilder6appendERKNS_10StringDataENS_6Date_tE]+0x29): undefined reference to `mongo::BSONObjBuilder::appendDate(mongo::StringData const&, mongo::Date_t)' 
fetcher.o: In function `mongo::BSONObjBuilder::obj()': 
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder3objEv[_ZN5mongo14BSONObjBuilder3objEv]+0x4c): undefined reference to `mongo::msgasserted(int, char const*)' 
fetcher.o: In function `mongo::BSONObjBuilder::_done()': 
fetcher.cpp:(.text._ZN5mongo14BSONObjBuilder5_doneEv[_ZN5mongo14BSONObjBuilder5_doneEv]+0x62): undefined reference to `mongo::BSONObjBuilderValueStream::endField(mongo::StringData const&)' 
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::claimReservedBytes(int)': 
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE18claimReservedBytesEi]+0x52): undefined reference to `mongo::invariantFailed(char const*, char const*, unsigned int)' 
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::grow_reallocate(int)': 
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x663): undefined reference to `mongo::msgasserted(int, char const*)' 
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEE15grow_reallocateEi]+0x6ed): undefined reference to `mongo::msgasserted(int, char const*)' 
fetcher.o: In function `mongo::checkFieldName(mongo::StringData)': 
fetcher.cpp:(.text._ZN5mongo14checkFieldNameENS_10StringDataE[_ZN5mongo14checkFieldNameENS_10StringDataE]+0x56): undefined reference to `mongo::uasserted(int, char const*)' 
fetcher.o: In function `mongo::_BufBuilder<mongo::TrivialAllocator>::_BufBuilder(int)': 
fetcher.cpp:(.text._ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei[_ZN5mongo11_BufBuilderINS_16TrivialAllocatorEEC2Ei]+0x5e): undefined reference to `mongo::msgasserted(int, char const*)' 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [qq_crawler] Error 1 

回答

0

把你的目標文件的庫之前:

clang -stdlib=libc++ main.o qqlogin.o fetcher.o -L/usr/lib -lcurl -lpthread 
    -ljsoncpp -lboost_system -lboost_regex -lmongoclient -o qq_crawler 
+0

它沒有工作。謝謝你。我在另一個問題上發表了我的細節。我會在一分鐘內刪除它。 –