Undefined Reference to Symbol '_Zn5Boost6System15System_Categoryev' Error

undefined reference to symbol '_ZN5boost6system15system_categoryEv' /

You should pass boost libraries to the target_link_libraries command. The smallest change to your file will be as follows:

target_link_libraries(qttest ${QT_LIBRARIES} ${LIBS})

But since you are using find_package for Boost and you do not actually use your LIBS variable anywhere, you should stick with something like this:

find_package(Boost COMPONENTS system REQUIRED)
...
target_link_libraries(qttest ${QT_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES})

And remove LIBS altogether.

undefined reference to symbol '_ZN5boost6system15system_categoryEv' error

/usr/lib/libboost_system.so.1.60.0: error adding symbols: DSO missing from command line

This DSO error means that libboost_system is missing from the command line.
You should also add:

-lboost_system

to your command line just like -lcpprest

undefined reference to symbol '_ZN5boost6system15system_categoryEv'

Oh my. You have many problems here. As Jesper said, linker issues are normally not related to #include files.

First, you should never add libraries to your compile lines: that is, lines that create object files (lines that use the -c compiler option). So this rule:

obj/%.o: src/%.cpp
@mkdir -p obj
@g++ -std=c++11 -DBOOST_ALL_DYN_LINK -pthread -lboost_log -lboost_thread -lboost_system -lboost_log_setup -lboost_filesystem -c $< -o $@

is wrong: you should not have any library options here (-l or -L). It should just be:

obj/%.o: src/%.cpp
@mkdir -p obj
@g++ -std=c++11 -DBOOST_ALL_DYN_LINK -c $< -o $@

However, all of this is irrelevant because none of this makefile is actually used except for one rule: the one that creates the program. You've created a bunch of variables that are never used, and a bunch of pattern rules which are ever used.

Next, you should never use quotes inside a makefile variable unless that variable contains an entire shell script that requires quotes. Make itself doesn't care about quotes, it just treats them the same as any other character. So, you should use:

PROGNAME := program

Next you should use the variable in the target, else it has no purpose:

bin/$(PROGNAME): ./bin lib/libStat.a src/main.cpp $(HEADERS)

And in your recipe you should use $@ to refer to the target.

Next, the order in which libraries are listed on the link line is critically important, and it must be more general libraries first, and libraries they depend on afterwards. So for example, your library Stat should come first, followed by Boost libraries, and finally at the end system libraries:

@g++ -std=c++11 src/main.cpp -DBOOST_ALL_DYN_LINK -pthread -L lib -l Stat -lboost_log -lboost_log_setup -lboost_thread -lboost_system -o bin/$(PROGNAME) -I /inc -I /usr/include/boost/log/utility/setup

Note that your -I option is wrong; you wrote -I /inc but you want (I assume) -I ./inc.

I have no idea why you're linking files from the source directory to the include directory. Maybe if you fix your -I option, you won't need to do this anymore.

Compiling C++ code with boost library

You are almost there. Add

-lboost_system

to your link line to yield (now with indentation)

$(CC) $(FLAGS) $(OBJS)  ipMT.o -o ipmt \
-L$(BOOSTLIB) -lboost_date_time -lboost_thread -lboost_system

The error message gave you a hint: No symbol '_ZN5boost6system15system_categoryEv' which indicates that

  1. the symbol came from the Boost System namespace, hence suggesting that you need to link this, and
  2. offering a hint via a tool like c++filt

If you have c++filt you can see the mangled identifier expanded:

edd@max:~$ c++filt _ZN5boost6system15system_categoryEv
boost::system::system_category()
edd@max:~$

Undefined Reference to Symbol 'Symbol' ... Error Adding Symbols: DSO Missing From Command Line (With CMake)

You should try changing this call to target_link_libraries:

target_link_libraries(cfucr-libs PRIVATE
configurator-libs
control-libs
filter-libs
math-utilities-libs
type-libs
tinyxml2
eigen
)

to use PUBLIC instead:

target_link_libraries(cfucr-libs PUBLIC
configurator-libs
control-libs
filter-libs
math-utilities-libs
type-libs
tinyxml2
eigen
)

With PRIVATE, the listed libraries (e.g. configurator-libs) are not made part of the link interface. So, consuming CMake targets (e.g. your executable) will not have visibility of these libraries and their definitions. With PUBLIC, the listed libraries are added to the link interface, so your executable oneLinkAdaptive consumes them also when you link cfucr-libs to it.

I encourage you to read through the target_link_libraries documentation, particularly the linked section describing the differences between the scoping keywords (i.e. PUBLIC, PRIVATE, etc).



Related Topics



Leave a reply



Submit