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.
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()'
try:
set(BOOST_ROOT <where you built boost>)
find_package(Boost COMPONENTS program_options signals thread system)
find_package(Threads)
...
target_link_libraries(target ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(target PUBLIC SYSTEM ${Boost_INCLUDE_DIRS})
remove these:
boost_signals
boost_thread
boost_program_options
boost_system
pthread
documentation here: https://cmake.org/cmake/help/v3.0/module/FindBoost.html
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})
Undefined reference to boost::system
As you don't have Boost 1.66, you need to link against boost::system:
add_executable(main main.cpp)
target_link_libraries(main ${Boost_SYSTEM_LIBRARY})
Related Topics
How to Calculate the Week Number Given a Date
How to Concatenate Two Strings in C++
How to Start a Cuda App in Visual Studio 2010
Where Do "Pure Virtual Function Call" Crashes Come From
How to Read a Value from the Windows Registry
How to Initialize Std::Vector from C-Style Array
How to Use Base Class'S Constructors and Assignment Operator in C++
How to Get the Argument Types of a Function Pointer in a Variadic Template Class
Compiling Multithread Code With G++
Iterate Vector, Remove Certain Items as I Go
Conditional Operator Differences Between C and C++
Why Compiler Doesn't Allow Std::String Inside Union
Is There a Reason to Call Delete in C++ When a Program Is Exiting Anyway
/Usr/Lib/Libstdc++.So.6: Version 'Glibcxx_3.4.15' Not Found
Creating All Possible K Combinations of N Items in C++