Dreaded linker error. Boost and catkin_make
Hey there, I am creating my own package with Boost, and I have a .cpp file that is able to compile using g++ with:
g++ newboost.cpp -o boost -lboost_system -lpthread
But, when I try to put the .cpp file into my package and catkin_make my package, I get the following error:
/usr/bin/ld: CMakeFiles/keyencelaser_node.dir/src/newboost.cpp.o: undefined reference to symbol 'pthread_create@@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
keyencelaser/CMakeFiles/keyencelaser_node.dir/build.make:95: recipe for target '/home/ateator/catkin_ws/devel/lib/keyencelaser/keyencelaser_node' failed
make[2]: *** [/home/ateator/catkin_ws/devel/lib/keyencelaser/keyencelaser_node] Error 1
CMakeFiles/Makefile2:4463: recipe for target 'keyencelaser/CMakeFiles/keyencelaser_node.dir/all' failed
make[1]: *** [keyencelaser/CMakeFiles/keyencelaser_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
which is a similar error to the one I got before adding the flags onto the g++ terminal command
I have tried to add Boost into my CMakeLists.txt, but (although it did improve my errors), I am still left with the above errors. My CMakeLists.txt is:
find_package(catkin REQUIRED COMPONENTS
roscpp
)
find_package(
Boost
REQUIRED COMPONENTS system thread
)
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(keyencelaser_node src/newboost.cpp)
target_link_libraries(keyencelaser_node
${Boost_FILESYSTEM_LIBRARIES}
${Boost_SYSTEM_LIBRARY}
)
I am pretty sure it's a linker error but I don't know how to fix it. Again, the edits I made to my CMakeLists.txt eliminated a lot of "undefined reference to" errors, but now that those are gone, I am left with the above. I appreciate any and all help.
Thank you.
just tried adding set (CMAKE_CXX_FLAGS "-lboost_system") and set(CMAKE_CXX_FLAGS "-lpthread") to my CMakeLists, but the error remains the same
Not an answer, but seeing the references to Keyence & lasers: have you seen ros-industrial/keyence_experimental? Needs some work, but might be interesting / save you some work.
I looked at it, but they use a different laser with a different protocol. That and I have a strong need for the code to be simple (1 file), among more issues. Thank you for checking, though.