帮助编译和使用boost c++图书馆
我正在开发一个 C++ 项目,我想在其中使用 boost 的序列化库。我从boost的主页下载并安装了最新的boost库。
当我尝试编译并运行 boost 的演示序列化示例之一时,我遇到了各种各样的错误,如下所示:
/usr/local/include/boost/archive/detail/iserializer.hpp:173: undefined reference to `boost::archive::archive_exception::~archive_exception()'
./demo.o: In function `void boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<bus_schedule::trip_info>(boost::archive::text_oarchive&, bus_schedule::trip_info const&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:253: undefined reference to `boost::archive::detail::basic_oarchive::save_object(void const*, boost::archive::detail::basic_oserializer const&)'
./demo.o: In function `void boost::archive::save_access::end_preamble<boost::archive::text_oarchive>(boost::archive::text_oarchive&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:83: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
./demo.o: In function `void boost::archive::detail::load_pointer_type<boost::archive::text_iarchive>::invoke<bus_route*>(boost::archive::text_iarchive&, bus_route*&)':
/usr/local/include/boost/archive/detail/iserializer.hpp:518: undefined reference to `boost::archive::detail::basic_iarchive::load_pointer(void*&, boost::archive::detail::basic_pointer_iserializer const*, boost::archive::detail::basic_pointer_iserializer const* (*)(boost::serialization::extended_type_info const&))'
./demo.o: In function `void boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::non_polymorphic::save<bus_route>(boost::archive::text_oarchive&, bus_route&)':
我是 C++ 和 boost 的新手,因此我们将不胜感激。
谢谢
I am working on a C++ project where I'd like to use boost's serialization libraries. I downloaded and installed the latest boost libraries from boost's home page.
When I tried to compile and run the one of boost's demo serialization examples, I got all sorts of errors that looked like this:
/usr/local/include/boost/archive/detail/iserializer.hpp:173: undefined reference to `boost::archive::archive_exception::~archive_exception()'
./demo.o: In function `void boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<bus_schedule::trip_info>(boost::archive::text_oarchive&, bus_schedule::trip_info const&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:253: undefined reference to `boost::archive::detail::basic_oarchive::save_object(void const*, boost::archive::detail::basic_oserializer const&)'
./demo.o: In function `void boost::archive::save_access::end_preamble<boost::archive::text_oarchive>(boost::archive::text_oarchive&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:83: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
./demo.o: In function `void boost::archive::detail::load_pointer_type<boost::archive::text_iarchive>::invoke<bus_route*>(boost::archive::text_iarchive&, bus_route*&)':
/usr/local/include/boost/archive/detail/iserializer.hpp:518: undefined reference to `boost::archive::detail::basic_iarchive::load_pointer(void*&, boost::archive::detail::basic_pointer_iserializer const*, boost::archive::detail::basic_pointer_iserializer const* (*)(boost::serialization::extended_type_info const&))'
./demo.o: In function `void boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::non_polymorphic::save<bus_route>(boost::archive::text_oarchive&, bus_route&)':
I am new to C++ and boost so any help would be appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
想必您需要链接到序列化库。在
/usr/lib
中查找名称类似于libboost_serialization
的内容。然后告诉g++
(你没有说你正在使用哪个编译器)你想使用(链接到)这个库:g++ main.cpp -lboost_serialization
即如果名称该库的文件是
/usr/lib/libboost_serialization.a
您省略了初始lib
和扩展名。祝你好运!
Presumably you need to link to the serialization library. Have a look in
/usr/lib
for something with a name similar tolibboost_serialization
. Then tellg++
(you didn't say which compiler you are using) you want to use (link to) this library:g++ main.cpp -lboost_serialization
I.e. if the name of the library is
/usr/lib/libboost_serialization.a
you leave out the initiallib
and the extension.Good luck!
感谢大家的帮助。我终于解决了我的问题,尽管我的解决方案相当反高潮,而且可能没有那么丰富的信息。
我尝试手动安装boost库,直接从boost的网站下载它们,发现所有库都安装在 /usr/local/lib 和 /usr/local/include/boost/ 中。在反复遇到最初的错误后,我决定看看 Synaptic 包管理器是否可以“更好”地安装 boost 库。我选择“libboost1.40-all-dev”来安装所有内容,但仍然没有任何效果。
最后,我决定重新开始,因此手动删除了 /usr/local/include 中的 boost/ 目录,并删除了 /usr/local/lib 中的所有 libboost 文件。然后,我将所有 boost 库标记为完全删除,以删除所有内容。卸载所有 boost 库后,我返回 Synaptic Package Manager,再次选择“libboost1.40-all-dev”。
我不确定当我再次重新安装库时到底发生了什么变化,但一切又开始工作了。我首先从命令行进行测试,并尝试使用以下命令再次编译 boost 网站上的 demo.cpp:
并立即编译。运行可执行文件完全显示了我正在寻找的结果。此外,我将文件移回到 Eclipse 项目中,将“boost_serialization”添加到链接器库中,并尝试构建该项目。一切再次完美运行,因为我可以构建项目并运行示例代码。
我并没有真正解释为什么这解决了我的问题,但对于遇到类似问题的其他人,我能给的最好建议是不要直接安装 boost 库,而是让 Synaptic 包管理器处理所有事情。
再次感谢大家,你们非常有帮助。
Thank you everyone for all your help. I finally got my problem solved, though my solution is fairly anti-climactic, and probably not that informative.
I had tried to install the boost libraries manually, by downloading them from boost's website directly, and found that all the libraries had been installed in /usr/local/lib, and /usr/local/include/boost/ . After repeatedly running into my original errors, I decided to see if the Synaptic Package Manager could do a 'better' job of installing the boost libraries. I selected 'libboost1.40-all-dev' to install everything, but still nothing was working.
Finally, I decided to start fresh so manually deleted the boost/ directory in /usr/local/include, and I deleted all the libboost files in /usr/local/lib. I then marked all the boost libraries for complete removal to remove everything. Once all the boost libraries were uninstalled, I went back to the Synaptic Package Manager, selected 'libboost1.40-all-dev' one more time.
I am not sure what exactly changed when I re-installed the libraries again, but everything started to work again. I first tested from the command line, and tried to compile the demo.cpp from boost's website one more time with the following command:
and it compiled immediately. Running the executable displayed exactly the results I was looking for. Furthermore, I moved the file back into my Eclipse project, added 'boost_serialization' to the Linker libraries, and tried to build the project. Everything worked perfectly again, as I could build the project and run the example code.
I don't really have an explanation for why this fixed my problem, but to anyone else experiencing similar problems, the best advice I can give is to NOT install the boost libraries directly, but rather have the Synaptic Package Manager handle everything.
Thanks again everyone, you've been extremely helpful.
您需要链接到 Boost.Serialization 库。请参阅 Boost 的入门页面。
You need to link to Boost.Serialization library. See the Boost's getting started page.