MacOSX 10.10.3 Yosemite

时间:2015-06-08 16:34:45

标签: c++ mongodb boost

我在使用MacOSX上的mongo C ++驱动程序编译代码时遇到了一些问题 它是使用CMake控制的大型项目的一部分

以下是我所面临的错误:

Undefined symbols for architecture x86_64:
 "mongo::msgasserted(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
  mongo::BSONObj::_assertInvalid() const in libworker.a(mongo_handler.cpp.o)
  mongo::BSONElement::chk(int) const in libworker.a(mongo_handler.cpp.o)
 "std::__1::basic_string<char, std::__1::char_traits<char>,       std::__1::allocator<char> > mongo::integerToHex<int>(int)", referenced from:
  mongo::BSONObj::_assertInvalid() const in libworker.a(mongo_handler.cpp.o)
 "mongo::causedBy(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
  mongo::DBException::addContext(std::__1::basic_string<char,  std::__1::char_traits<char>, std::__1::allocator<char> > const&) in   libworker.a(mongo_handler.cpp.o)
 "mongo::uasserted(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
  mongo::BSONArrayBuilder::fill(mongo::StringData const&) in libworker.a(mongo_handler.cpp.o)
  mongo::BSONElement::toString(mongo::StringBuilderImpl<mongo::TrivialAllocator>&, bool, bool, int) const in libworker.a(mongo_handler.cpp.o)
 "mongo::UserException::appendPrefix(std::__1::basic_stringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) const", referenced from:
  vtable for mongo::ConnectException in libworker.a(mongo_handler.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/test/worker/test_dbmanager] Error 1
make[1]: *** [test/worker/CMakeFiles/test_dbmanager.dir/all] Error 2
make: *** [all] Error 2

安装依赖项:

1)使用brew

提升库1.57

2)使用的scons选项:(在26compat分支上提取最新版本的驱动程序。目标MongoDB版本2.6.5

sudo apt-get install scons
git clone https://github.com/mongodb/mongo-cxx-driver.git

#checkout the stable 2.6 drivers
cd mongo-cxx-driver
git checkout 26compat

#compile the drivers
sudo scons --full --use-system-boost --sharedclient install-mongoclient

3)我使用的代码片段并导致了问题

#include <mongo/client/dbclient.h>
//... some class definitions and declarations
mongo::DBClientConnection m_connection;
void MongoRequestHandler::connect(const std::string& host_and_port) {
    m_connection.connect(host_and_port);
}

4)代码在Linux Ubuntu 14.04上编译得非常好

非常感谢任何帮助!

修改

我已根据建议添加了链接选项:

-fPIC -msse3 -std=c++11 -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-    headerpad_max_install_names      CMakeFiles/test_dbmanager.dir/test_dbmanager.cpp.o  -o ../../bin/test/worker/test_dbmanager  ../../lib/libworker.a   ../../lib/libengine.dylib ../../lib/libutls.a ../../lib/libimageutls.a /usr/local/lib/libjpeg.dylib /usr/local/lib/libpng.dylib   /usr/lib/libz.dylib /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_thread-mt.dylib   /usr/local/lib/libboost_filesystem-mt.dylib  /usr/local/lib/libmongoclient.dylib ../../lib/libcompression.a ../../lib/libutls.a ../../lib/libaffpts.a /usr/local/Cellar/flann/1.8.4/lib/libflann.dylib /usr/local/lib/libjpeg.dylib /usr/local/lib/libpng.dylib /usr/lib/libz.dylib ../../lib/libmessage.a -lthrift /usr/local/lib/libboost_system-mt.dylib /usr/local/lib/libboost_thread-mt.dylib /usr/local/lib/libboost_filesystem-mt.dylib /usr/local/lib/libmongoclient.dylib

修改

问题已解决,

这是由于不正确的scons标志被传递给编译。 Scons假设10.6是osx的最低版本,它在libstdc ++上构建库,设置--osx-version-min = 10.10,将强制使用libc ++,而不是10.10上链接的默认lib。

0 个答案:

没有答案