I have no trouble building my application under Visual Studio's environment, but due to lack of experience, I am having trouble under Linux/GCC. Although GCC compiles my app successfully, but it reports linker errors.
The first thing I did was to build a shared library using CMakeLists.txt. The file has no ‘make install’ so I manually copied the shared library file to a global location as follows:
sudo cp libibpp.a /usr/local/lib/
Since applications built with the IBPP library require you to include a single header file, I copied it to a global location:
sudo cp ibpp.h /usr/local/include/
So far, so good but when I run CMake for my application, I am getting linker errors such as:
undefined reference to ‘isc_create_database’
I am successfully using many ‘shared libraries’ in my application (such as Boost Regex/Filesystem/Chrono/DateTime/Thread). The only ‘static library’ that I am using is IBPP (libibpp.a).
I suspect that I am missing something in my application’s CMakeListst.txt:
cmake_minimum_required(VERSION 3.10.2)
project(myapp)
file(GLOB src "*.h" "*.cpp")
add_executable(myapp ${src})
target_link_libraries(myapp ibpp icuuc icudata boost_regex boost_system boost_filesystem
boost_chrono boost_date_time boost_thread pthread)
add_definitions(-DIBPP_LINUX)
Can someone provide me with some hints as to why I get linker errors related to IBPP?
UPDATED:
User n.m. asked me to build using the VERBOSE option, so here is the output:
/usr/bin/cmake -E cmake_link_script CMakeFiles/myapp.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/myapp.dir/appServer.cpp.o CMakeFiles/myapp.dir/app_env.cpp.o CMakeFiles/myapp.dir/app_setting.cpp.o CMakeFiles/myapp.dir/authenticationServer.cpp.o CMakeFiles/myapp.dir/bustacheTestStencil.cpp.o CMakeFiles/myapp.dir/commonKeys.cpp.o CMakeFiles/myapp.dir/dataFetcher.cpp.o CMakeFiles/myapp.dir/fighterKeys.cpp.o CMakeFiles/myapp.dir/fighterProfileJsonGenerator.cpp.o CMakeFiles/myapp.dir/fighterProfileMarkupGenerator.cpp.o CMakeFiles/myapp.dir/fighterStorage.cpp.o CMakeFiles/myapp.dir/forwardProxyServer.cpp.o CMakeFiles/myapp.dir/headerProcessor.cpp.o CMakeFiles/myapp.dir/homepageStencil.cpp.o CMakeFiles/myapp.dir/httpUtils.cpp.o CMakeFiles/myapp.dir/locale.cpp.o CMakeFiles/myapp.dir/main.cpp.o CMakeFiles/myapp.dir/markupServer.cpp.o CMakeFiles/myapp.dir/myTools.cpp.o CMakeFiles/myapp.dir/stdafx.cpp.o CMakeFiles/myapp.dir/unicodeFunctions.cpp.o CMakeFiles/myapp.dir/utils.cpp.o -o myapp -libpp -licutu -licutest -licuio -licui18n -licuuc -licudata -lboost_regex -lboost_system -lboost_filesystem -lboost_chrono -lboost_date_time -lbustache -lboost_thread -lpthread
//usr/local/lib/libibpp.a(_ibpp.cpp.o): In function `ibpp_internals::GDS::Call()':
_ibpp.cpp:(.text+0x2c): undefined reference to `isc_create_database'
_ibpp.cpp:(.text+0x3b): undefined reference to `isc_attach_database'
....
_ibpp.cpp:(.text+0x2bd): undefined reference to `isc_service_start'
_ibpp.cpp:(.text+0x2cf): undefined reference to `isc_service_query'
collect2: error: ld returned 1 exit status
CMakeFiles/myapp.dir/build.make:640: recipe for target 'myapp' failed
make[2]: *** [myapp] Error 1
make[2]: Leaving directory '/home/carol/Documents/vm_shared/AppServer/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/myapp.dir/all' failed
make[1]: *** [CMakeFiles/myapp.dir/all] Error 2
make[1]: Leaving directory '/home/carol/Documents/vm_shared/AppServer/build'
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Problem solved thanks to comment by n.m. above. Since I was not including libfbclient, I was getting the "undefined references to 'isc_create_database', and other 'isc_...' messages.
Using the settings below, I am now able to use my precompiled/built IBPP library instead of having to include the source code into my application!
Here is a simplified, very barebones CMakeLists.txt that demonstrates what is required to get your IBPP.a implemented into your app without having to include the IBPP source into your app:
file(GLOB src "*.cpp")
add_executable(myapp ${src})
target_link_libraries(myapp ibpp fbclient)
Make note of the order, libibpp must be before libfbclient.
Related
I am trying to compile Azure storage c++ SDK on Fedora 22. I am using gcc version 5.1.1-1. When I compile test application using following command:
$> CASABLANCA_DIR=/source/codebox/azure/cpprestsdk/ CXX=g++ cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=on
$> make
It produces following error message:
/usr/bin/ld: CMakeFiles/azurestoragetest.dir/main.cpp.o: undefined reference to symbol 'pthread_rwlock_wrlock##GLIBC_2.2.5'
/usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
tests/CMakeFiles/azurestoragetest.dir/build.make:879: recipe for target 'Binaries/azurestoragetest' failed
make[2]: *** [Binaries/azurestoragetest] Error 1
CMakeFiles/Makefile2:125: recipe for target 'tests/CMakeFiles/azurestoragetest.dir/all' failed
make[1]: *** [tests/CMakeFiles/azurestoragetest.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
make: *** [all] Error 2
I can see libpthread.so.0 library in /usr/lib64 directory. Which other library I need to install?
Add the right find_package invokation to your CMakeLists.txt:
find_package(Threads)
Then, link the library to your target:
target_link_libraries(my_target ${CMAKE_THREAD_LIBS_INIT})
That's all. Likely you forgot the target_link_libraries.
In general (outside of CMake and Azure Storage SDK), this error indicates you need to link with -lpthread. (With gcc you likely want -pthread.)
I am attempting to build the AR Drone SDK on Ubuntu. When compiling the libraries I get the error:
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I dont understand what the problem is. I am following this tutorial and the problem occurs when I run make. I have run ARDroneLib/Soft/Build/check_dependencies.sh and it outputs ok.
Any ideas what the problem is? Below is the full output from running make.
soribo#soribo-vm:~/Projects/ARDrone/ARDrone_SDK_2_0_1/Examples/Linux$ make
make[1]: Entering directory `/home/soribo/Projects/ARDrone/ARDrone_SDK_2_0_1/ARDroneLib/Soft/Build'
Libs already extracted
Building target static
Architecture x86_64 is already built
Creating universal static lib file from architectures x86_64
Build done.
Checking required Ubuntu packages ...
ok.
Building ARDroneTool/Lib
Building ARDroneTool/Lib
make[1]: Leaving directory `/home/soribo/Projects/ARDrone/ARDrone_SDK_2_0_1/ARDroneLib/Soft/Build'
make[1]: Entering directory `/home/soribo/Projects/ARDrone/ARDrone_SDK_2_0_1/Examples/Linux/Navigation/Build'
-- Building ardrone_navigation --
Libs already extracted
Building target static
Architecture x86_64 is already built
Creating universal static lib file from architectures x86_64
Build done.
Checking required Ubuntu packages ...
ok.
Building ARDroneTool/Lib
Building ARDroneTool/Lib
-- Linking ardrone_navigation --
ld common/mobile_main
/usr/bin/ld: ../../Soft/Build/targets_versions/ffmpeg_static_PROD_MODE_Linux_3.19.0-25-generic_GNU_Linux_usrbingcc_4.8.4/libavutil.a(eval.o): undefined reference to symbol 'fabs##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[4]: *** [/home/soribo/Projects/ARDrone/ARDrone_SDK_2_0_1/Examples/Linux/Navigation/Build/../../Build/Release/common/mobile_main] Error 1
make[3]: *** [all] Error 2
make[2]: *** [build_app] Error 2
make[1]: *** [ardrone_navigation] Error 2
make[1]: Leaving directory `/home/soribo/Projects/ARDrone/ARDrone_SDK_2_0_1/Examples/Linux/Navigation/Build'
make: *** [all] Error 2
I had the same problem. I found the solution here:
http://jderobot.org/Varribas-tfm/ARDrone:starting_up#Building_Examples
Looking for undefined reference to symbol 'fabs##GLIBC_2.2.5', I reached to [2], that confirms an unmeet dependency problem [1].
What happened here?
libavutil.a(eval.o): undefined reference to symbol 'fabs##GLIBC_2.2.5'
libm.so.6: error adding symbols: DSO missing from command line
First line say us that libavutil is using fabs. It is declared into libm library, but -lm is missed in command line (Makefile).
ARDrone_SDK_2_0_1/Examples/Linux/Navigation/Build/Makefile:131
GENERIC_LIBS+=-liw -lpc_ardrone -lgthread-2.0 -lgtk-x11-2.0 -lrt -lxml2 -ludev -lswscale -lSDL -lm
Then, Navigation will compile successfully.
I'm trying to build a hand model library from libhand.org on Ubuntu 14.04. The library uses ogre and opencv libraries. I followed the instructions provided by the author that allowed me to successfully install ogre and opencv. There is no problem with cmake .. . but during execute command
make -j4
I get the following error:
[ 87%] Building CXX object source/CMakeFiles/hand_renderer.dir/hand_pose.cc.o
[ 91%] Building CXX object source/CMakeFiles/hand_renderer.dir/scene_spec.cc.o
Linking CXX static library libhand_renderer.a
[ 91%] Built target hand_renderer
Scanning dependencies of target pose_designer
[ 95%] Building CXX object source/CMakeFiles/pose_designer.dir/pose_designer_main.cc.o
[100%] Building CXX object source/CMakeFiles/pose_designer.dir/pose_designer.cc.o
Linking CXX executable pose_designer
/usr/bin/ld: cannot find -lNOTFOUND
/usr/bin/ld: cannot find -lNOTFOUND
libhand_utils.a(file_dialog.cc.o): In function
`libhand::FileDialog::TkExec(std::string const&)':
file_dialog.cc:(.text+0xead): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
collect2: error: ld returned 1 exit status
make[2]: *** [source/pose_designer] Error 1
make[1]: *** [source/CMakeFiles/pose_designer.dir/all] Error 2
make: *** [all] Error 2
Does anyone know why this error occurs and what can be done?
I assume this error occurs because some required library was not found during the run of cmake but that incident was not correctly detected (ie. cmake did not abort with an error). More details on that should be available in a file named CMakeError.log or CMakeOutput.log in the CMakeFiles directory.
The solution to this problem is either installing the missing library (which name should be available from the aforementioned files) or fix the build process to find the library, if it is already installed (for autotools, this would be using the CFLAGS and LDFLAGS environment variables to point to the correct include paths, compiler options, library paths and libraries; that should also work with CMake).
As an alternative explanation, cmake found the library but somehow failed to write the correct Makefiles. Then the solution would be manually replacing -lNOTFOUND by -l<library name> in the Makefiles.
I'm trying to make a file in Ubuntu and when i make i keep getting this error:
/usr/bin/ld: ../../gtest-1.7.0/libgtest.a(gtest-all.cc.o): undefined reference to symbol 'pthread_key_delete##GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [src/tests/run_tests] Error 1
make[1]: *** [src/tests/CMakeFiles/run_tests.dir/all] Error 2
make: *** [all] Error 2
I saw someone mentioning to go into Makefile and adding '-L /lib64 -l pthread' to the variable LDFLAGS but how do you do that? Totally new to linux here =X
The above linking problem is solved by adding
-lpthread -lm to CMakeLists.txt (target link libraries for luxrender);
TARGET_LINK_LIBRARIES(... -lpthread -lm)
I hit the same issue: -lpthread should be last in your linking invocation
(has to do with mix of static and shared symbols)
So with CMake: ${CMAKE_THREAD_LIBS_INIT} should be last. For example:
target_link_libraries(mytestlib
${BINARY_DIR}/libgmock.a
glog
gflags
${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
And for the OP: Search for "thread" in the CMakeLists.txt for the project your are building and paste those section (or link which project you are trying to build if it is open source) - if the above isn't self explanatory
If you are building with Make or something else, add -pthread to the compilation command line (so GCC would generate thread-safe static locals) and to the linking command line (so GCC would tell the linker to do the right thing, most notably link with -lpthread).
If you are building with CMake - then most probably you need these (full example):
# always
FIND_PACKAGE(Threads REQUIRED)
# if using boost
SET(Boost_USE_MULTITHREADED ON)
TARGET_LINK_LIBRARIES(my_app ... ${CMAKE_THREAD_LIBS_INIT})
I have installed boost along with other dependencies needed for Cassandra cpp driver on my ubuntu 12.04 LTS. When I try to run command below it ends up with two errors. I have looked for solutions but can't find any. Some say to link in the libboost_system by adding the option -lboost_system which I tried, but doesn't help.
Here is the cmd: cmake . && make && make cql_demo && make cql_test && make test && make install -lboost_system
All i want to do is to run the demo from the driver and to communicate with the cassandra database!
Errors:
-- info CMAKE_BINARY_DIR: /home/pi/experiments/cpp-driver-master2
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/experiments/cpp-driver-master2
[ 42%] Built target cql
[ 85%] Built target cql_static
[ 87%] Built target CCMBridge
Linking CXX executable cql_integration_tests
/usr/bin/ld: warning: libboost_thread.so.1.55.0, needed by /usr/local/lib/libboost_log.so, may conflict with libboost_thread.so.1.46.1
/usr/bin/ld: CMakeFiles/cql_integration_tests.dir/src/test_utils.cpp.o: undefined reference to symbol 'boost::future_category()'
/usr/bin/ld: note: 'boost::future_category()' is defined in DSO /usr/local/lib/libboost_thread.so.1.55.0 so try adding it to the linker command line
/usr/local/lib/libboost_thread.so.1.55.0: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[2]: *** [test/integration_tests/cql_integration_tests] Error 1
make[1]: *** [test/integration_tests/CMakeFiles/cql_integration_tests.dir/all] Error 2
make: *** [all] Error 2
The following error:
/usr/bin/ld: warning: libboost_thread.so.1.55.0, needed by /usr/local/lib/libboost_log.so, may conflict with libboost_thread.so.1.46.1
is basically saying that you have two versions of Boost installed:
Custom built one in /usr/local/lib/, probably version 1.55.0.
Another one in system directories, probably version 1.46.1.
and when they both get linked to your binary version 1.46.1 wins.
You need to see all complete command lines that CMake invokes for you to tell exactly where the problem is.