C ++ Boost: undefined reference to boost :: system :: generic_category ()

I am trying to include Boost libraries in my project and run into problems in the same. I am on Ubuntu 12.10 with the Codeblocks IDE and tried to install the libraries manually by reading the instructions from the site, but I got an error with the header, as well as with libraries that must be built in before use.

Then I installed the libraries via terminalby sudo apt-get install libboost-all-dev . After that, in my Codeblocks programs, I can include headers like #include <boost/regex.hpp> , but when I try to include a header for the file system library ( #include "boost/filesystem/operations.hpp" ), I get the following error :

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

I am not sure how to resolve this error (especially in Codeblocks on Linux). I really could help here.

Compiler: Gcc
Program code: I tried only the specified operations.hpp file system file.

Assembly block of code blocks:

 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 
+78
c ++ boost linux codeblocks
Nov 20 '12 at 5:24
source share
12 answers

You must specify the link in the libboost_system library. I'm not sure about code blocks, but the g ++ command line option on your platform will be

-lboost_system

+129
Nov 20 '12 at 7:17
source share

Depending on the accelerated version, libboost-system comes with the -mt suffix, which should indicate the possibility of multithreading libraries.

Therefore, if -lboost_system cannot be found by the try linker try -lboost_system-mt .

+20
Sep 02 '13 at 8:07
source share

This is a linker problem. Include the static library path in your project.

For Qt Creator, open the .pro project file and add the following line:

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

In my case, Ubuntu x86_64:

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

For code blocks, open the Settings->Compiler...->Linker settings tab and add:

 boost_system 

to the link library text widget and click OK .

+8
Jun 02 '15 at 22:30
source share

I also looked for a solution, and none of the answers I came across resolved the error until I found the answer "ViRuSTriNiTy" to this thread: Undefined link to 'raise :: system :: generic_category ()'?

according to this answer, try adding these lines to your cmake file:

 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}) 
+7
Sep 29 '16 at 7:54 on
source share

The same problem when creating a simple boost example, was solved after I changed the g ++ compiler flag from -std = C ++ 14 to -std = C ++ 11 .

And I noticed that this is a C ++ 11 example ...

+2
Aug 16 '18 at 15:10
source share

This answer really helped when using Boost and cmake.

Adding add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) for the cmake file.

My CMakeLists.txt looks like this:

 cmake_minimum_required(VERSION 3.12) project(proj) set(CMAKE_CXX_STANDARD 17) set(SHARED_DIR "${CMAKE_SOURCE_DIR}/../shared") set(BOOST_LATEST_DIR "${SHARED_DIR}/boost_1_68_0") set(BOOST_LATEST_BIN_DIR "${BOOST_LATEST_DIR}/stage/lib") set(BOOST_LATEST_INCLUDE_DIR "${BOOST_LATEST_DIR}/boost") set(BOOST_SYSTEM "${BOOST_LATEST_BIN_DIR}/libboost_system.so") set(BOOST_FS "${BOOST_LATEST_BIN_DIR}/libboost_filesystem.so") set(BOOST_THREAD "${BOOST_LATEST_BIN_DIR}/libboost_thread.so") set(HYRISE_SQL_PARSER_DIR "${SHARED_DIR}/hyrise_sql_parser") set(HYRISE_SQL_PARSER_BIN_DIR "${HYRISE_SQL_PARSER_DIR}") set(HYRISE_SQL_PARSER_INCLUDE_DIR "${HYRISE_SQL_PARSER_DIR}/src") set(HYRISE_SQLPARSER "${HYRISE_SQL_PARSER_BIN_DIR}/libsqlparser.so") include_directories(${CMAKE_SOURCE_DIR} ${BOOST_LATEST_INCLUDE_DIR} ${HYRISE_SQL_PARSER_INCLUDE_DIR}) set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu/") set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) find_package(Boost 1.68.0 REQUIRED COMPONENTS system thread filesystem) add_executable(proj main.cpp row/row.cpp row/row.h table/table.cpp table/table.h page/page.cpp page/page.h processor/processor.cpp processor/processor.h engine_instance.cpp engine_instance.h utils.h meta_command.h terminal/terminal.cpp terminal/terminal.h) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(proj PUBLIC Boost::system Boost::filesystem Boost::thread ${HYRISE_SQLPARSER}) endif() 
+2
Oct 10 '18 at 9:52
source share

You may run into another problem. After installing Boost on Linux Mint, I had the same problem. The binding -lboost_system or -lboost_system-mt did not work because the library was named libboost_system.so.1.54.0 .

So, the solution is to create a symbolic link to the source file. In my case

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

See this question for more information.

+1
Feb 14 '15 at 14:22
source share

I had the same problem and also use Linux Mint (like nuduoz). The problem of my case was resolved after adding boost_system to GCC C++ Linker->Libraries .

+1
Aug 26 '15 at 10:11
source share

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 acceleration library

use find /usr/ -name '*boost*.so' to find the location of the acceleration library

0
Aug 2 '15 at 22:38
source share

g ++ -lboost_system -lboost_filesystem userentry.cpp -o userentry

worked great under debian. (c ++ acceleration libraries installed with apt-get).

0
Oct 08 '18 at 19:57
source share

Il library is not installed, you must provide a folder with extended libraries:

example:

g ++ -L / usr / lib / x86_64 -L inux-gnu -L boost_system -L boost_filesystem prog.cpp -o prog

0
Oct 08 '18 at 20:13
source share

After testing the proposed solutions described above, I found that only these few lines would work.

cmake_minimum_required (VERSION 3.13)
project (MyProject)

set (CMAKE_CXX_STANDARD 11)
add_executable (randomProject main.cpp)

find_package (Boost 1.58.0 REQUIRED COMPONENTS of the system file system)
target_link_libraries (myProject $ {Boost_LIBRARIES})

0
Apr 19 '19 at 17:23
source share



All Articles