C++中与LIGBOOGORDER链接时出错

C++中与LIGBOOGORDER链接时出错,c++,mongodb,c++11,boost,compiler-errors,C++,Mongodb,C++11,Boost,Compiler Errors,当我开始用clang编译代码时,libmongoclient似乎不存在。但是,我在这台ubuntu机器上编译了mongo cxx客户端的旧版本。此代码在我的Mac上正常工作 clang -lstdc++ -stdlib=libc++ -lcurl -lpthread -ljsoncpp -lboost_system -lboost_regex -lmongoclient -L/usr/lib main.o qqlogin.o fetcher.o -o qq_crawler 这是链接的代码。使用

当我开始用clang编译代码时,libmongoclient似乎不存在。但是,我在这台ubuntu机器上编译了mongo cxx客户端的旧版本。此代码在我的Mac上正常工作

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

将对象文件放在库之前:

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

它不起作用。谢谢你。我已经在另一个问题中发布了我的详细信息。我将在一分钟内删除它。