Error building mpi2 - trouble linking libboost_system - c++

I am trying to build mpi2 and encounter the following error during make:
/usr/bin/ld: CMakeFiles/env.dir/env.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/local/boost-1.56.0/lib/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The cmake command I used prior to running make was:
cmake -DCMAKE_BUILD_TYPE=NativeRelease ../ -DBOOST_ROOT=/usr/local/boost-1.56.0/ -DBOOST_INCLUDEDIR=/usr/local/boost-1.56.0/include -DBOOST_LIBRARYDIR=/usr/local/boost-1.56.0/lib
I have tried linking against libboost_system.so, but I'm unsure how to do this with cmake (I tried adding -DCMAKE_CXX_FLAGS="-lboost_system" to the cmake command, but this had no effect).
How do I correctly link this with cmake to resolve this error?

I think the problem may be that Boost.System isn't listed as a requirement in the CMakeLists.txt.
Looking at https://github.com/uma-pi1/mpi2/blob/master/CMakeLists.txt#L67, it seems like system should be added immediately after chrono in the find_package(Boost ...) call.

Related

Linking a prebuilt binary in cpp does not work?

I just build the following package: faiss and my cpp program now recognises all library header so I can include them into my program. But my programm throws undefined reference to. So when I built faiss it created a libfaiss.a and a libfaiss.so which one to link and how??? I think I have tried any solution that I could find in the internet, but my knowledge of the build/linking process is limited.
My Faiss build-directory looks like this:
faiss-1.5.3/
-libfaiss.a
-libfaiss.so
-foo.h
-foo.o
-foo.cpp
-bar.h
-...
My tries. (I am using ROS, catkin_simple and gtests)
So this is how I would usually do it:
find_library(LibFaiss faiss HINT /home/tim/faiss/faiss-1_5_3/faiss-1.5.3/)
catkin_add_gtest(test_inverted_nn test/test_inverted-nn.cc
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}})
target_link_libraries(test_inverted_nn ${LIBRARY_NAME} ${LibFaiss})
I get the following Error:
/usr/bin/ld: cannot find -lLibFaiss-NOTFOUND}
collect2: error: ld returned 1 exit status
CMakeFiles/test_inverted_nn.dir/build.make:358: recipe for target '/home/tim/catkin_ws/devel/lib/nn/test_inverted_nn' failed
make[3]: *** [/home/tim/catkin_ws/devel/lib/inverted_nn/test_inverted_nn] Error 1
I also found this Solution here Import an external library into a ROS node, but that does not work for me:
add_library(libfaiss STATIC IMPORTED)
set_target_properties(libfaiss PROPERTIES IMPORTED_LOCATION /home/tim/faiss/faiss-1_5_3/faiss-1.5.3/libfaiss.a)
target_link_libraries(test_inverted_nn ${LIBRARY_NAME} ${libfaiss})
This throws the following Error:
/usr/bin/ld: cannot find -l}
collect2: error: ld returned 1 exit status
EDIT
After correcting the not_found error I am getting the following error:
CMake Warning at /opt/ros/melodic/share/catkin/cmake/test/gtest.cmake:180 (add_executable):
Cannot generate a safe runtime search path for target
test_inverted_multi_index because files in some directories may conflict
with libraries in implicit directories:
runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/usr/local/lib
Some of these libraries may not be found correctly.
*** It does not matter what I add inside target_link_libraries I am always getting that error***
EDIT2
So with the tipp of #Aconcagua I deleted everything from the CMakeLists.txt and only added the following to my cmake options:
-DCMAKE_CXX_FLAGS=-L/home/tim/faiss/faiss-1_5_3/faiss-1.5.3/
But Im still getting the undefined reference errors. It does not make any difference

ld cannot find library that exists

I'm trying to link my code to a library called clik. I'm passing the directory to ld with -L DIRECTORY and -lclik. DIRECTORY contains the file libclik.so. However, ld gives and error "ld: cannot find -lclik". Any ideas what could cause this?
To be more specific, I am using cmake. In cmake I have something like
find_library(CLIKLIB clik DIRECTORY)
and then for my executable I do:
target_link_libraries(executable ${CLIKLIB})
and that's how cmake generates the code for linking to clik but then ld fails.

Linker error while building from source code

I am trying to build an application from source. I am able to configure it using 'cmake .'. However, when I run 'make' it gives me this:
Linking CXX executable ../../bin/lux64/Release/od_batch_launcher
../../bin/lux64/Release/libBasic.so: undefined reference to `dlopen'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlclose'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlerror'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlsym'
../../bin/lux64/Release/libBasic.so: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/lux64/Release/od_batch_launcher] Error 1
make[1]: *** [src/Basic/CMakeFiles/od_batch_launcher.dir/all] Error 2
make: *** [all] Error 2
I understand that its is unable to dynamically link to a c++ library. I don't quite know how to make the necessary changes to cmake. I am running gcc version: 4.9.2 on Linux Mint 17. I would be grateful for any help. Thank you!
Try passing -DCMAKE_EXE_LINKER_FLAGS=-ldl to the CMake executable. To change the CMake build scripts, add something like:
target_link_libraries(target_name dl)
where target_name is basically the executable name without any extensions (e.g. .exe).
EDIT: Actually, I just reread you question, and I'm putting this in the wrong place. You really want:
target_link_libraries(Basic dl)
Apparently, there were also pthread-related errors, so you'd also have to add:
target_compile_options(Basic PUBLIC -pthread)
Both of these go in whichever file contains add_library(Basic) (usually CMakeLists.txt).
EDIT 2: Instead of target_compile_options, try:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

Issue with CMake project building

I have the following problem. On my Ubuntu I try to build a project and receive the following linker error(s) so far:
/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_thread.a(once.o): undefined reference to symbol 'pthread_once##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]: *** [sunprint] Error 1 make[1]: ***
[CMakeFiles/sunprint.dir/all] Error 2 make: *** [all] Error 2
*** Failure: Exit code 2 ***
I'm running under ubuntu 13 desktop, GCC 4.8, boost ver. is 1.54. As an IDE I'm working with
is the KDevelop.
I can provide any additional info about this issue if needed, but now I'm stuck with
this linking problem.
Any ideas?
Thanx in advance.
add_definitions only adds inputs for the preprocessor, which is in action even before the compiler starts its business and even much farther away from linking the executable, the step ld is supposed to be doing.
What you want to have ld resolve link-time dependencies is the CMake command target_link_libraries, which, for a given target, add a number of libs to link against after compilation.
In you case, the appropriate invocation could look like this
target_link_libraries(${PROJECT_NAME} [...] -lpthread [...]) #obviously without the '[...]' and the correct target name
I had a similar problem but with mpich. Both:
target_link_libraries(${PROJECT_NAME} [...] -lmpich [...])
and
target_link_libraries(${PROJECT_NAME} [...] mpich [...])
worked properly.

undefined reference linking yaml-cpp program with mingw-w64 + cmake

I'm using mingw-w64 (4.8.0) + cmake to build shared libraries for yaml-cpp (0.5.1). The project has a few build targets in the CMakeLists.txt that comes with it: the main library yaml-cpp and some test programs e.g. parse, which links the library.
The library target yaml-cpp itself built without error but it is followed by this error when parse is built:
Linking CXX executable parse.exe
CMakeFiles\parse.dir/objects.a(parse.cpp.obj):parse.cpp:(.text+0x1a3): undefined reference to `YAML::Load(std::istream&)'
CMakeFiles\parse.dir/objects.a(parse.cpp.obj):parse.cpp:(.text+0x1b2): undefined reference to `YAML::operator<<(std::ostream&, YAML::Node const&)'
c:/work/mingw64-4.8/bin/../lib/gcc/x86_64-w64-mingw32/4.8.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\parse.dir/objects.a(parse.cpp.obj): bad reloc address 0x0 in section `.data'
collect2.exe: error: ld returned 1 exit status
util\CMakeFiles\parse.dir\build.make:90: recipe for target 'util/parse.exe' failed
mingw32-make[3]: *** [util/parse.exe] Error 1
CMakeFiles\Makefile2:228: recipe for target 'util/CMakeFiles/parse.dir/all' failed
mingw32-make[2]: *** [util/CMakeFiles/parse.dir/all] Error 2
CMakeFiles\Makefile2:240: recipe for target 'util/CMakeFiles/parse.dir/rule' failed
mingw32-make[1]: *** [util/CMakeFiles/parse.dir/rule] Error 2
makefile:211: recipe for target 'parse' failed
mingw32-make: *** [parse] Error 2
I run into similar errors when I try to write small test programs using the library, and I don't know what is wrong. What might be the issue here?
Jesse Beder's comment points to the exact issue causing the error described in the question. A quick fix while this gets fixed in a follow-up release is to apply the patch (https://code.google.com/p/yaml-cpp/issues/detail?id=216#c4) to a clean copy of yaml-cpp 0.5.1. There is also a line that declares std::string node_data::empty_scalar in the source file src/node_data.cpp that should be commented out. After making these changes, the shared libraries and utilities build without error.