It is my first time using stack overflow so I am a bit new with this. I've been working on a personal robotics project and I have downloaded a GitHub directory. I've already compiled it, tested it (it works) and I've generated the library.a
file (because I'm working with Ubuntu 16.04 and ROS Kinetic). What I do not know is what I have to add to my CMakeLists.txt
file in order to load the communication functions on a ROS node cpp file.
My actual description for compilation on the CMakeLists.txt
file is the following one:
...
add_executable(test_node src/test_node.cpp)
add_dependencies(test_node ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_node ${catkin_LIBRARIES})
...
I know that I have to add the library on the target_link_libraries if the library was an *.so
file, but it isn't. What should I add to my CMakeLists.txt
file in order to load my library functions into my ROS node?
Your answer is based in a property on function add_library()
See this example block:
add_library(library_name STATIC IMPORTED)
set_target_properties(library_name PROPERTIES IMPORTED_LOCATION path/to/your/lib.a)
With this you can proceed to add this library with:
target_link_libraries(your_target library_name)
But don't forget to add this static library include files to your target.
The problem is solved with the following code:
...
find_package(Threads)
add_library(github_library STATIC IMPORTED GLOBAL)
set_target_properties(my_library PROPERTIES IMPORTED_LOCATION
my_library_directory/my_library.a)
...
target_link_libraries(my_cpp_ros_node ${catkin_LIBRARIES} my_library ${CMAKE_THREAD_LIBS_INIT})
...