未定义对“boost::archive ...”的引用 g++ / wsl
Posted
技术标签:
【中文标题】未定义对“boost::archive ...”的引用 g++ / wsl【英文标题】:undefined reference to "boost::archive..." g++ / wsl 【发布时间】:2020-06-11 09:04:08 【问题描述】:我同时使用 draco 和 boost。在question 之后,Draco 工作得很好。
我已经尝试安装 boost,我认为它已经完成了。
现在我尝试在 wsl 上的 vs-code 中运行这个命令:
g++ -I ~/local/include -L ~/local/lib -o prog ObjContainer.cpp -ldracodec -lboost_system
错误:
ObjContainer.cpp:(.text._ZN5boost7archive6detail15common_iarchiveINS0_15binary_iarchiveEED2Ev[_ZN5boost7archive6detail15common_iarchiveINS0_15binary_iarchiveEED5Ev]+0x22): undefined reference to `boost::archive::detail::basic_iarchive::~basic_iarchive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char, std::char_traits<char> >::~binary_iarchive_impl()':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEED2Ev[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEED5Ev]+0x32): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::~basic_binary_iprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::char_traits<char> >::binary_oarchive_impl(std::ostream&, unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC2ERSoj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC5ERSoj]+0x55): undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::basic_binary_oprimitive(std::basic_streambuf<char, std::char_traits<char> >&, bool)'
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC2ERSoj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEEC5ERSoj]+0xab): undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::~basic_binary_oprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_iarchive_impl<boost::archive::binary_iarchive, char, std::char_traits<char> >::binary_iarchive_impl(std::istream&, unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC2ERSij[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC5ERSij]+0x55): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::basic_binary_iprimitive(std::basic_streambuf<char, std::char_traits<char> >&, bool)'
ObjContainer.cpp:(.text._ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC2ERSij[_ZN5boost7archive20binary_iarchive_implINS0_15binary_iarchiveEcSt11char_traitsIcEEC5ERSij]+0xab): undefined reference to `boost::archive::basic_binary_iprimitive<boost::archive::binary_iarchive, char, std::char_traits<char> >::~basic_binary_iprimitive()'
/tmp/ccqY0aGT.o: In function `boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::char_traits<char> >::init(unsigned int)':
ObjContainer.cpp:(.text._ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEE4initEj[_ZN5boost7archive20binary_oarchive_implINS0_15binary_oarchiveEcSt11char_traitsIcEE4initEj]+0x21): undefined reference to `boost::archive::basic_binary_oarchive<boost::archive::binary_oarchive>::init()'
【问题讨论】:
【参考方案1】:boost::archive
类是 Boost.Serialization 库的一部分。
最后需要链接-lboost_serialization -lboost_system
。
【讨论】:
以上是关于未定义对“boost::archive ...”的引用 g++ / wsl的主要内容,如果未能解决你的问题,请参考以下文章
boost::archive::xml_oarchive 中的 class_id