Linux C++ Boost:对 boost::system::generic_category() 的未定义引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13467072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ Boost: undefined reference to boost::system::generic_category()
提问by Cipher
I am trying to include Boost
libraries in my project and have been facing issues in the same. I am on Ubuntu 12.10 with Codeblocks IDE and tried installing the libraries manually reading instructions from the site, but was getting error's with header as well as to-be-built-before-use libraries.
我正在尝试Boost
在我的项目中包含库,并且一直面临着同样的问题。我在使用 Codeblocks IDE 的 Ubuntu 12.10 上尝试手动安装库,从站点读取指令,但在使用头文件和使用前要构建的库时遇到错误。
I then installed the libraries via terminalby sudo apt-get install libboost-all-dev
. After this, in my programs on Codeblocks, I can include headers like #include <boost/regex.hpp>
but when I try to include the header for the Filesystem library ( #include "boost/filesystem/operations.hpp"
), I am getting the following error:
然后我通过 terminalby 安装了这些库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()'|
I am not sure how to resolve this error (specifically in Codeblocks on Linux). I really could use some help here.
我不确定如何解决此错误(特别是在 Linux 上的代码块中)。我真的可以在这里使用一些帮助。
Compiler : Gcc
Program code: Only tried inlcuding the above file system operations.hpp
file.
编译器:Gcc
程序代码:只尝试包含上述文件系统operations.hpp
文件。
Build log from 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
采纳答案by juanchopanza
You should link in the libboost_system
library. I am not sure about codeblocks, but the g++ command-line option on your platform would be
你应该在libboost_system
图书馆里链接。我不确定代码块,但是您平台上的 g++ 命令行选项是
-lboost_system
-lboost_system
回答by tssch
Depending on the boost version libboost-system comes with the -mt suffix which should indicate the libraries multithreading capability.
根据 boost 版本,libboost-system 带有 -mt 后缀,它应该表示库的多线程能力。
So if -lboost_system
cannot be found by the linker try -lboost_system-mt
.
因此,如果-lboost_system
链接器找不到,请尝试-lboost_system-mt
.
回答by nuduoz
You could come across another problem. After installing Boost on the Linux Mint I've had the same problem. Linking -lboost_system
or -lboost_system-mt
haven't worked because library have had name libboost_system.so.1.54.0
.
你可能会遇到另一个问题。在 Linux Mint 上安装 Boost 后,我遇到了同样的问题。链接-lboost_system
或-lboost_system-mt
没有工作,因为图书馆有 name libboost_system.so.1.54.0
。
So the solution is to create symbolic link to the original file. In my case
所以解决方案是创建指向原始文件的符号链接。就我而言
sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0 /usr/lib/libboost_system.so
For more information see thisquestion.
有关更多信息,请参阅此问题。
回答by GLR
It's a linker problem. Include the static library path into your project.
这是链接器问题。将静态库路径包含到您的项目中。
For Qt Creator open the project file .pro
and add the following line:
对于 Qt Creator,打开项目文件.pro
并添加以下行:
LIBS += -L<path for boost libraries in the system> -lboost_system
In my case Ubuntu x86_64:
就我而言,Ubuntu x86_64:
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system
For Codeblocks, open up Settings->Compiler...->Linker
settings tab and add:
对于代码块,打开Settings->Compiler...->Linker
设置选项卡并添加:
boost_system
to the Link libraries text widget and press OKbutton.
到链接库文本小部件并按下OK按钮。
回答by algometrix
try
尝试
g++ -c main.cpp && g++ main.o /usr/lib/x86_64-linux-gnu/libboost_system.so && ./a.out
/usr/lib/x86_64-linux-gnu/
is the location of the boost library
/usr/lib/x86_64-linux-gnu/
是boost库的位置
use find /usr/ -name '*boost*.so'
to find the boost library location
用于find /usr/ -name '*boost*.so'
查找 boost 库位置
回答by piotr93
I had the same problem and also use Linux Mint (as nuduoz) . I my case problem was solved after i added boost_system
to GCC C++ Linker->Libraries
.
我有同样的问题,也使用 Linux Mint (as nuduoz) 。我添加boost_system
到GCC C++ Linker->Libraries
.
回答by SubMachine
I searched for a solution as well, and none of the answers I encountered solved the error, Until I found the answer of "ViRuSTriNiTy" to this thread: Undefined reference to 'boost::system::generic_category()'?
我也搜索了一个解决方案,但我遇到的所有答案都没有解决该错误,直到我找到了“ViRuSTriNiTy”到此线程的答案:未定义对 'boost::system::generic_category()' 的引用?
according to that answer, try to add these lines to your cmake file:
根据该答案,尝试将这些行添加到您的 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})
回答by Halowb
Same problem on building a simple boost example, solved after i changed the g++ compiler flag from -std=c++14to -std=c++11.
在构建一个简单的 boost 示例时遇到了同样的问题,在我将 g++ 编译器标志从-std=c++14更改为-std=c++11 后解决了。
And I noticed that it's a C++11 Example...
我注意到它是一个 C++11 示例......
回答by majukarma
g++ -lboost_system -lboost_filesystem userentry.cpp -o userentry
g++ -lboost_system -lboost_filesystem userentry.cpp -o userentry
worked perfectly under debian. (boost c++ libraries installed with apt-get).
在 debian 下完美运行。(使用 apt-get 安装的 boost C++ 库)。
回答by Majukarma
Il the library is not installed you should give boost libraries folder:
Il 库未安装,您应该提供 boost 库文件夹:
example:
例子:
g++ -L/usr/lib/x86_64-linux-gnu -lboost_system -lboost_filesystem prog.cpp -o prog
g++ -L/usr/lib/x86_64-linux-gnu -lboost_system -lboost_filesystem prog.cpp -o prog