Undefined reference to boost :: system :: system_category () at compilation

I am trying to compile a program on Ubuntu 11.10 that uses Boost libraries. I have the 1.46-dev Boost libraries from the Ubuntu repository, but I get an error message when compiling the program.

undefined reference to boost::system::system_category()

What am I doing wrong?

+100
c ++ boost
Mar 15 '12 at 16:18
source share
9 answers

The acceleration library you use depends on the boost_system library. (Not all of them do.)

Assuming you are using gcc, try adding -lboost_system to your compiler command line to link to this library.

+156
Mar 15 '12 at 16:32
source share

Linking to a library that defines the missing character ( -lboost_system ) is an obvious solution, but in the particular Boost.System case, the inaccuracy in the original project forces us to use boost::system::generic_category() and boost::system::system_category() unnecessarily . Compiling with the -DBOOST_SYSTEM_NO_DEPRECATED flag disables this code and allows you to compile several programs without requiring -lboost_system (this link, of course, is still necessary if you explicitly use some of the library functions).

Starting with Boost 1.66 and this commit , this behavior is now the default, so hopefully fewer and fewer users will have to answer this question.

As @AndrewMarshall noted, an alternative is to define BOOST_ERROR_CODE_HEADER_ONLY which allows a version of the code for the header only. However, this is not recommended by Boost, as it may interfere with some functions.

+58
Jun 16 '15 at 20:38
source share

Another workaround for those who don't need the whole shebang: use the switch

-DBOOST_ERROR_CODE_HEADER_ONLY .

If you use CMake, this is add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY) .

+17
May 03 '18 at 4:01
source share

The above error is a linker error ... linker is a program that accepts one or more objects generated by the compiler and combines them into one executable program.

You should add '-l boost_system' to the linker flags, which tells the linker that it should look for symbols like boost::system::system_category() in the libboost_system.so library

If you have main.cpp, either:

 g++ main.cpp -o main -lboost_system 

OR

 g++ -c -o main.o main.cpp g++ main.o -lboost_system 
+16
Mar 15 '12 at 16:44
source share

When using CMAKE and find_package, make sure this is:

 find_package(Boost COMPONENTS system ...) 

but not

 find_package(Boost COMPONENTS system ...) 

Some people may have lost hours for this ...

+7
Jun 30 '16 at 13:06
source share

I have the same problem:

 g++ -mconsole -Wl,--export-all-symbols -LC:/Programme/CPP-Entwicklung/MinGW-4.5.2/lib -LD:/bfs_ENTW_deb/lib -static-libgcc -static-libstdc++ -LC:/Programme/CPP-Entwicklung/boost_1_47_0/stage/lib \ D:/bfs_ENTW_deb/obj/test/main_filesystem.obj \ -o D:/bfs_ENTW_deb/bin/filesystem.exe -lboost_system-mgw45-mt-1_47 -lboost_filesystem-mgw45-mt-1_47 

D: /bfs_ENTW_deb/obj/test/main_filesystem.obj :. Main_filesystem.cpp :( text + 0x54): undefined reference to `boost :: system :: generic_category ()

The solution was to use the debug version of system-lib:

 g++ -mconsole -Wl,--export-all-symbols -LC:/Programme/CPP-Entwicklung/MinGW-4.5.2/lib -LD:/bfs_ENTW_deb/lib -static-libgcc -static-libstdc++ -LC:/Programme/CPP-Entwicklung/boost_1_47_0/stage/lib \ D:/bfs_ENTW_deb/obj/test/main_filesystem.obj \ -o D:/bfs_ENTW_deb/bin/filesystem.exe -lboost_system-mgw45-mt-d-1_47 -lboost_filesystem-mgw45-mt-1_47 

But why?

+6
Nov 13 '12 at 16:59
source share

When I had this problem, the reason was the ordering of the libraries. To fix this, I put libboost_system last:

 g++ mingw/timer1.o -o mingw/timer1.exe -L/usr/local/boost_1_61_0/stage/lib \ -lboost_timer-mgw53-mt-1_61 \ -lboost_chrono-mgw53-mt-1_61 \ -lboost_system-mgw53-mt-1_61 

This was in mingw with gcc 5.3 and boost 1.61.0 with a simple timer example.

+4
Mar 16 '17 at 14:08
source share

in my case, adding -lboost_system was not enough, it still could not find it in my custom build environment. I had to use the advice Get rid of "gcc - / usr / bin / ld: warning lib not found" and change the ./configure command to:

 ./configure CXXFLAGS="-I$HOME/include" LDFLAGS="-L$HOME/lib -Wl,-rpath-link,$HOME/lib" --with-boost-libdir=$HOME/lib --prefix=$HOME 

see Boost 1.51 for more details : "error: failed to associate with boost_thread!"

+2
Feb 22 '14 at 16:50
source share

... and if you want to link your core statically, in your Jamfile add the following requirements:

 <link>static <library>/boost/system//boost_system 

and possibly also:

 <linkflags>-static-libgcc <linkflags>-static-libstdc++ 
+1
Nov 13 '12 at 15:12
source share



All Articles