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

我正在尝试在我的项目中joinBoost库,并且一直面临相同的问题。 我使用的是Codeblocks IDE的Ubuntu 12.10,并尝试安装库手动读取站点的指令,但遇到错误的标题,以及即将build成之前使用的库。

然后,我通过sudo apt-get install libboost-all-dev安装了库。 在这之后,在Codeblocks的程序中,我可以包含像#include <boost/regex.hpp>这样的头#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文件。

从Codeblocks生成日志:

 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 

你应该链接libboost_system库。 我不确定codeblocks,但在你的平台上的g ++命令行选项将是

-lboost_system

取决于boost版本libboost-系统带有-mt后缀,它应该表明库multithreading能力。

因此,如果连接器try -lboost_system-mt

这是一个链接器的问题。 将静态库path包含到您的项目中。

对于Qt Creator打开项目文件.pro并添加以下行:

 LIBS += -L<path for boost libraries in the system> -lboost_system 

在我的情况下Ubuntu x86_64:

 LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system 

对于Codeblocks,打开Settings->Compiler...->Linker设置选项卡,并添加:

 boost_system 

链接库文本部件,然后按确定button。

你可能会遇到另一个问题。 在Linux Mint上安装Boost后,我遇到了同样的问题。 链接-lboost_system-lboost_system-mt没有工作,因为库名称为libboost_system.so.1.54.0

所以解决scheme是创build原始文件的符号链接。 在我的情况

 sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0 /usr/lib/libboost_system.so 

有关更多信息,请参阅此问题。

我有同样的问题,也使用Linux Mint(作为nuduoz)。 我的案例问题解决后,我添加boost_system GCC C++ Linker->Libraries

我寻找一个解决scheme,以及没有我遇到的答案解决了错误,直到我find了“ViRuSTriNiTy”这个线程的答案: 未定义的引用'boost :: system :: generic_category()'?

根据这个答案,尝试将这些行添加到您的cmake文件中:

 find_package(Boost 1.55.0 REQUIRED COMPONENTS system filesystem) include_directories(... ${Boost_INCLUDE_DIRS}) link_directories(... ${Boost_LIBRARY_DIRS}) target_link_libraries(... ${Boost_LIBRARIES}) 

尝试

 g++ -c main.cpp && g++ main.o /usr/lib/x86_64-linux-gnu/libboost_system.so && ./a.out 

/usr/lib/x86_64-linux-gnu/是boost库的位置

使用find /usr/ -name '*boost*.so'来查找boost库位置