How to link to third party library ?
Hello
I'm still working on the communication between ROS electric and Promethe Neural Network simulator and I'm trying to rosmake a node that includes Promethe C functions. I'm using the following CMakeLists.txt :
I can rosmake witjout error but I get :
[rosmake-0] Finished <<< promROS_connector [SKIP] No rule to make target None
And no executable in bin/ . I would know if my CMakeLists is correct and what I exactly have to use to compile with third party C compiled libraries. The ~/simulateur is in ROS_PACKAGE_PATH.
Thanks for reading and answering.
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()
#common commands for building c++ executables and libraries
#****************** INCLUDES **************************
include_directories(~/simulateur/prom_user/include)
include_directories(~/simulateur/libcomm/include)
include_directories(~/simulateur/libcomm/include/protocol/virtual)
include_directories(~/simulateur/prom_tools/include)
include_directories(~/simulateur/prom_kernel/include)
include_directories(~/simulateur/shared/include)
#*******************************************************
link_directories(~/simulateur/lib/Linux/comm)
rosbuild_add_executable(prom2ROS src/prom_to_ROS.cpp)
target_link_libraries(prom2ROS ~/simulateur/lib/Linux/comm/libcomm_debug)
EDIT :
After using :
target_link_libraries(prom2ROS libcomm_debug)
the error is :
Linking CXX executable ../bin/prom2ROS
/usr/bin/ld: cannot find -llibcomm_debug
collect2: ld returned 1 exit status
Does I have to set the LD_LIBRARY_PATH to allow ld to find the libcomm_debug (it is now empty - libcomm_debug is a .a static library) ?
Does
target_link_libraries(prom2ROS -lcomm_debug)
work? (libcomm_debug is already prebuild?)Also, what is: promROS_connector? The ~/simulateur doesn't need to be in the package path as it is not a ROS package (right? otherwise you should like via export flags in the manifest)
@dornhege: remove the '-l' prefix, that should work. CMake expects library names in
target_link_libraries
, it is not a direct replacement for what you'd write in a linking statement forld
, as CMake performs dependency resolution on the listed libraries.Yes, that's nicer.
target_link_libraries(prom2ROS libcomm_debug) is better in the sense that it throw an error - I'm editing the message for more details. Thanks for help.
@Erwan R.: see my edit, I forgot to remove the
lib
prefix.Done, it works ! Many many thanks !