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
- the symbol came from the Boost System namespace, hence suggesting that you need to link this, and
- 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
Cmake Error: "Add_Subdirectory Not Given a Binary Directory"
Communication Between Native-App and Chrome-Extension
Under What Circumstances Is It Advantageous to Give an Implementation of a Pure Virtual Function
Cannot Open Windows.H in Microsoft Visual Studio
Std::Lower_Bound Slower for Std::Vector Than Std::Map::Find
Template Metaprogramming: (Trait For) Dissecting a Specified Template into Types T<T2,T3 N,T4, ...>
Are There in X86 Any Instructions to Accelerate Sha (Sha1/2/256/512) Encoding
Good Refactoring Support for C++
How to Do Password Authentication for a User Using Ldap
Capturing H264 Stream with Opencv
Std::Istream_Iterator<> with Copy_N() and Friends
In C++, Is There a Difference Between "Throw" and "Throw Ex"
How to Sort C++ Array in Asc and Desc Mode
Opencv Cvsaveimage Jpeg Compression Factor
Std::Thread - "Terminate Called Without an Active Exception", Don't Want to 'Join' It
What's the Purpose of a Leading "::" in a C++ Method Call
Lnk2022 Metadata Operation: Inconsistent Layout Information in Duplicated Types