简体   繁体   English

为什么我不能编译 Boost.Serialization 演示?

[英]Why can't I compile the Boost.Serialization demo?

I am running Ubuntu 16.04.我正在运行 Ubuntu 16.04。 I'm trying to get Boost.Serialization set up, and I'm running into trouble compiling the first demo from the tutorial (titled A Very Simple Case).我正在尝试设置 Boost.Serialization,但在编译教程中的第一个演示(标题为一个非常简单的案例)时遇到了麻烦。 I have followed the Boost Getting Started page for installing Boost and building Serialization, doing the following:我已经按照 Boost 入门页面安装 Boost 和构建序列化,执行以下操作:

  • download the code from SourceForge (I have tried different versions including 1.67.0 and 1.55.0)SourceForge下载代码(我尝试过不同的版本,包括 1.67.0 和 1.55.0)
  • cd boost_1_55_0
  • ./bootstrap.sh --prefix=/usr/local --with-libraries=serialization
  • sudo ./b2 install
  • check that /usr/local/include and /usr/local/lib include the relevant Boost files检查/usr/local/include/usr/local/lib包含相关的 Boost 文件

and then I compile demo.cpp using然后我编译demo.cpp使用

g++ -o demo demo.cpp -I /usr/local/include/boost -l boost_serialization

and get the following error:并得到以下错误:

/tmp/cc9a7HRg.o: In function boost::archive::text_iarchive::text_iarchive(std::istream&, unsigned int)': demo.cpp:(.text._ZN5boost7archive13text_iarchiveC2ERSij[_ZN5boost7archive13text_iarchiveC5ERSij]+0x36): undefined reference to boost::archive::detail::shared_ptr_helper::shared_ptr_helper()' /tmp/cc9a7HRg.o: In function boost::archive::text_iarchive::~text_iarchive()': demo.cpp:(.text._ZN5boost7archive13text_iarchiveD2Ev[_ZN5boost7archive13text_iarchiveD5Ev]+0x24): undefined reference to boost::archive::detail::shared_ptr_helper::~shared_ptr_helper()' collect2: error: ld returned 1 exit status /tmp/cc9a7HRg.o: 在函数boost::archive::text_iarchive::text_iarchive(std::istream&, unsigned int)': demo.cpp:(.text._ZN5boost7archive13text_iarchiveC2ERSij[_ZN5boost7archive13text_iarchiveC5ERSij]+0x36): undefined reference to ::archive::detail::shared_ptr_helper::shared_ptr_helper()' /tmp/cc9a7HRg.o: 在函数boost::archive::text_iarchive::~text_iarchive()': demo.cpp:(.text._ZN5boost7archive13text_iarchiveD2Ev[_ZN5boost7archive13text_iarchiveD5Ev]+0x24): undefined reference to boost::archive::detail::shared_ptr_helper::~shared_ptr_helper()' collect2 的boost::archive::text_iarchive::~text_iarchive()': demo.cpp:(.text._ZN5boost7archive13text_iarchiveD2Ev[_ZN5boost7archive13text_iarchiveD5Ev]+0x24): undefined reference to :错误:ld 返回 1 个退出状态

The line causing the error is导致错误的行是

boost::archive::text_iarchive ia(ifs);

It is worth mentioning that the output line值得一提的是输出线

boost::archive::text_oarchive oa(ofs);

was causing a similar error before the most recent re-install.在最近的重新安装之前导致了类似的错误。 Also, if I comment out all of the input (including the line causing the error), the program compiles fine, but causes a segmentation fault upon running.此外,如果我注释掉所有输入(包括导致错误的行),程序编译正常,但在运行时会导致分段错误。 I have included cout << "done" << endl;我已经包括cout << "done" << endl; at the end of main , but it is not reached.main的末尾,但未到达。

Does anybody know what might be causing this error?有人知道可能导致此错误的原因吗? Sorry if this seems like a silly question.对不起,如果这似乎是一个愚蠢的问题。 I am very new to C++ development.我对 C++ 开发很陌生。 Thank you in advance!先感谢您!

sudo apt-get install libboost-all-dev

worked for me.为我工作。

This command is taken from the same source as lboyd's solution: https://www.technical-recipes.com/2012/getting-started-with-the-boost-libraries-in-ubuntu-linux/此命令取自与 lboyd 的解决方案相同的来源: https ://www.technical-recipes.com/2012/getting-started-with-the-boost-libraries-in-ubuntu-linux/

then I compile with然后我编译

g++ serialization.cpp -lboost_serialization -lboost_system

对于遇到此问题的任何其他人,我设法通过手动卸载我从源代码安装的所有内容(从/usr/locale/include//usr/local/lib/以及根 Boost目录)并按照此处所述使用apt-get安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM