对“boost::system::system_category()”的未定义引用

Undefined reference to "boost::system::system_category()"

提问人:yphs 提问时间:10/11/2013 最后编辑:hauzeryphs 更新时间:10/11/2013 访问量:7311

问:

obj\Debug\src\SQLite3DB.o||In function _static_initialization_and_destruction_0:|
D:\workspace-cpp\boost_1_54_0_beta1\boost\system\error_code.hpp|222|undefined reference to boost::system::generic_category()|
D:\workspace-cpp\boost_1_54_0_beta1\boost\system\error_code.hpp|223|undefined reference to boost::system::generic_category()|
D:\workspace-cpp\boost_1_54_0_beta1\boost\system\error_code.hpp|224|undefined reference to boost::system::system_category()|
||=== Build finished: 3 errors, 0 warnings (0 minutes, 4 seconds) ===|

以上是我包含在我的项目后的完整错误消息。我看到一些帖子说添加可能会解决这个问题,但我不知道在 CodeBlocks 中在哪里执行此操作!
我已经花了一天时间解决这个问题。感谢您的帮助!
boost/filesystem.hpp-lboost_system

C++ Boost Codeblocks 未定义引用

评论

0赞 Adriano Repetti 10/11/2013
如何链接到带有 Code::Blocks 的库的可能重复项?
0赞 yphs 10/11/2013
我只是在链接器中添加了 -lboost_system,但它出现此错误“没有这样的文件或字典”。我该怎么办?

答:

2赞 hauzer 10/11/2013 #1

右键单击项目名称;点击“构建选项...”;转到“链接器设置”;点击“添加”;找到库并添加它。

enter image description here enter image description here enter image description here enter image description here

此外,您可以添加一些自定义变量来简化调试/发布和 32/64 位目标选项的管理。我就交给你了。


编辑

这是来自的错误代码:error_code.hpp

# ifndef BOOST_SYSTEM_NO_DEPRECATED
    inline const error_category &  get_system_category() { return system_category(); }
    inline const error_category &  get_generic_category() { return generic_category(); }
    inline const error_category &  get_posix_category() { return generic_category(); }
    static const error_category &  posix_category = generic_category();
    static const error_category &  errno_ecat     = generic_category();
    static const error_category &  native_ecat    = system_category();
# endif

如您所见,定义将禁用它。我已经测试过了,它有效。这将编译:BOOST_SYSTEM_NO_DEPRECATED

#define BOOST_SYSTEM_NO_DEPRECATED
#include <boost/system/error_code.hpp>

int main(void)
{

}

评论

0赞 yphs 10/11/2013
..\..\..\..\Boost\1_54_0\VC\11.0\bin.v2\libs\system\build\msvc-11.0\debug\link-static\threading-multi\libboost_system-vc110-mt-gd-1_54.lib -- 将它添加到链接器设置后,它仍然出现相同的错误!