Linking shared libraries
I've got some troubles with building my draft for a package i'm working on. I know my program is working, when compiling with eclipse everything runs smoothly. But somehow cmake won't link my shared library i'm using.
Here's my CMakeLists.txt:
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
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
include_directories("~/fuerte_workspace/can_bus/include")
include_directories("~/fuerte_workspace/can_bus/include/mhstcan_essentials")
rosbuild_add_executable(TEST test.cpp src/weCAN_BUS.cpp src/mhstcan_essentials/util.c src/mhstcan_essentials/linux_util.c src/mhstcan_essentials/can_drv.c)
#target_link_libraries(example ${PROJECT_NAME})
#LINK_DIRECTORIES(~/fuerte_workspace/can_bus/libs)
#add_library(TEST mhstcan ~/fuerte_workspace/can_bus/libs/mhstcan.so)
TARGET_LINK_LIBRARIES(TEST ~/fuerte_workspace/can_bus/libs/mhstcan.so)
Now, when i'm running make or rosmake i get
"make[3]: *** No rule to make target »../libs/mhstcan.so«, needed by »../bin/TEST«, Stop."
when i uncomment the add library line i'll get:
CMake Error at /opt/ros/fuerte/share/ros/core/rosbuild/public.cmake:495 (add_executable):
Cannot find source file:
mhstcan
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
Call Stack (most recent call first):
CMakeLists.txt:32 (rosbuild_add_executable)
CMakeLists.txt:35 (add_library)
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
-- Build files have been written to: /../fuerte_workspace/can_bus/build
I hope you can help me, i don't know what to google anymore :/
P.S.: All the big and bold stuff should be commented with a hash
add_library will build a library from the provided sources files, which is not what you want. The target_link_libraries is the right way to go.