C++ Boost: Undefined Reference to Boost::System::Generic_Category()

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

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

-lboost_system

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

The boost library you are using depends on the boost_system library. (Not all of them do.)

Assuming you use gcc, try adding -lboost_system to your compiler command line in order to link against that library.

Undefined reference to boost::system::generic_category() although libs are given to g++

Your build command is in the wrong order, and order matters.

GCC reads left-to-right, taking symbols from libraries when it already knows it needs them. As you put program.cpp last, you don't make that known until all listed libraries have already been identified and discarded.

Put program.cpp first, then the libraries it needs.

g++ -o program program.cpp -lboost_filesystem -ldl -lboost_system

Yes, it's kind of weird. (Even weirder that it worked on Debian! Though apparently only some "recent" Linuxy distributions default --as-needed on, which is what causes the behaviour you see, showing that the behaviour isn't necessarily guaranteed. Perhaps Debian 9 just outright does not do that.)


More info:

  • Why does the order in which libraries are linked sometimes cause errors in GCC?

why undefined reference to `boost::system::generic_category even if I do link against boost_system

The order at which you link your libraries matters, in your case you have library.cpp that apparently uses the boost_system library

library.cpp:(.text+0x25f): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x269): undefined reference to `boost::system::generic_category()'
library.cpp:(.text+0x273): undefined reference to `boost::system::system_category()'

To solve this you should move the boost_system library to the end of your link line

g++ -o build/myproject build/main/main.o -L/usr/local/boost/boost_1_52_0/boost/libs -L/usr/lib -Lbuild -L. -lboost_thread -lpthread -lboost_regex -lpq -lmylibrary **-lboost_system** 

Alternatively, build libmylibrary.so as a shared library and link to the boost_system library directly.

undefined reference to `boost::system::generic_category()' when adding boost/asio

The -l option is not a compiler option, it's a linker options, so you're setting it for the wrong variable as CMAKE_CXX_FLAGS are only for the compiler.

Instead use e.g. target_link_libraries to add libraries. Like

target_link_libraries(rcp boost_system)

But what you really should do is to find the system-installed Boost libraries and use those. You do that with find_package:

find_package(Boost
REQUIRED COMPONENTS asio system)

include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(rcp ${Boost_LIBRARIES})


Related Topics



Leave a reply



Submit