Ask Your Question

Linking shared libraries

asked 2013-04-28 01:05:24 -0500

Karl_Auer gravatar image

updated 2013-04-29 04:51:32 -0500

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)

# 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)


#set the default path for built executables to the "bin" directory
#set the default path for built libraries to the "lib" directory

#uncomment if you have defined messages
#uncomment if you have defined services

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_link_boost(${PROJECT_NAME} thread)

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})
#add_library(TEST mhstcan ~/fuerte_workspace/can_bus/libs/
TARGET_LINK_LIBRARIES(TEST ~/fuerte_workspace/can_bus/libs/

Now, when i'm running make or rosmake i get

"make[3]: *** No rule to make target »../libs/«, 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:


  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:


-- 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

edit retag flag offensive close merge delete



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.

dornhege gravatar image dornhege  ( 2013-04-28 06:28:03 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-04-28 01:33:40 -0500

ipso gravatar image

Have you seen this previously answered question?

edit flag offensive delete link more


That should be the problem: split link_directories and the linked library into two commands.

dornhege gravatar image dornhege  ( 2013-04-28 06:27:17 -0500 )edit

/usr/bin/ld: cannot find -lmhstcan
collect2:ld returned l exit status that's what i'm getting now

Karl_Auer gravatar image Karl_Auer  ( 2013-04-29 04:25:56 -0500 )edit

ah okay i've got it. Had the wrong order in my CMakeLists.txt. Thx for the advice!

Karl_Auer gravatar image Karl_Auer  ( 2013-04-29 04:54:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-04-28 01:05:24 -0500

Seen: 5,110 times

Last updated: Apr 29 '13