Ask Your Question
0

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

edit retag flag offensive close merge delete

Comments

3

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
2

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

ipso gravatar image

Have you seen this previously answered question?

edit flag offensive delete link more

Comments

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

Stats

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

Seen: 5,110 times

Last updated: Apr 29 '13