2
  1. Boost 由以下人员安装和制作:brew install boost
  2. 将标题路径添加/usr/local/Cellar/boost/1.53.0/include到用户标题搜索路径
  3. 将库路径添加/usr/local/Cellar/boost/1.53.0/lib到库搜索路径

主文件

#include <fstream>
#include <sstream>
#include <string>
#include "test.cpp"

void test(){
    Test instance(true, 'm', 50, 17.89, "fuzhijie");
    stringstream binary_sstream; 
    boost::archive::binary_oarchive binary_oa(binary_sstream);
    binary_oa << instance;
}

int main(int argc, const char * argv[])
{
    test();
    return 0;
}

当我按 CTRL+b 时,显示以下错误消息:

Undefined symbols for architecture x86_64:
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init()", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::init(unsigned int) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      void boost::archive::save_access::save_primitive<boost::archive::binary_oarchive, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(boost::archive::binary_oarchive&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::basic_binary_oprimitive(std::__1::basic_streambuf<char, std::__1::char_traits<char> >&, bool)", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
  "boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~basic_binary_oprimitive()", referenced from:
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::~binary_oarchive_impl() in main.o
      boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::__1::char_traits<char> >::binary_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人对如何解决这个问题有任何建议吗?

4

1 回答 1

0

原因可能是你有编译器 gcc5 或 gcc6。并且您的代码在您的 boost 库中使用了不同的编译标志。详细请阅读此链接

如果您可以重新编译您使用的所有不兼容的库,请使用编译器选项

-D_GLIBCXX_USE_CXX11_ABI=1

然后重建你的项目。如果仍然无法链接,请将更改项目的 makefile 编译器选项添加为 0。

-D_GLIBCXX_USE_CXX11_ABI=0

======更新=======

真正的解决方案应该是为 gcc6 或 gcc5 安装新的 boost 库 (v1.62)。

于 2017-04-28T15:49:12.267 回答