C Boost:对 boost::system::generic_category() 的未定义引用

新手上路,请多包涵

我试图在我的项目中包含 Boost 库,并且一直面临同样的问题。我在带有 Codeblocks IDE 的 Ubuntu 12.10 上,并尝试手动安装库,从站点读取说明,但在标头和使用前构建的库中出现错误。

然后我通过终端安装了库 sudo apt-get install libboost-all-dev 。在此之后,在我的代码块程序中,我可以包含像 #include <boost/regex.hpp> 这样的标题,但是当我尝试包含文件系统库的标题( #include "boost/filesystem/operations.hpp" )时,我收到以下错误:

 /usr/include/boost/system/error_code.hpp|214|undefined reference to boost::system::generic_category()'|

我不确定如何解决此错误(特别是在 Linux 上的 Codeblocks 中)。我真的可以在这里使用一些帮助。

编译器:GCC

程序代码:仅尝试包含上述文件系统 operations.hpp 文件。

从代码块构建日志:

 Build started on: 20-11-2012 at 18:02.53
Build ended on: 20-11-2012 at 18:02.54
-------------- Build: Debug in libopenFrameworks ---------------
Target is up to date.
-------------- Build: Debug in reader1 ---------------
make -s -f Makefile Debug
linking i686 bin/reader1_debug linux
obj/i686Debug/src/testApp.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
obj/i686Debug/src/main.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [bin/reader1_debug] Error 1
Process terminated with status 2 (0 minutes, 1 seconds)
6 errors, 0 warnings

原文由 Cipher 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
2 个回答

您应该在 libboost_system 库中链接。我不确定代码块,但您平台上的 g++ 命令行选项将是

-lboost_system

原文由 juanchopanza 发布,翻译遵循 CC BY-SA 3.0 许可协议

在我的项目中,我更喜欢使用仅标头库。所以上面没有任何帮助。真正有帮助的是:

 add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)

原文由 def 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题