Rosanswers logo

Hello everyone. I dont normally run to the forums for healp, but I have been dealing with an issue for two days and I am getting really frustrated. I am trying to interface with a LabJack from within a ROS node. The developers have published a .c file full of functions for native TCP operation. I have compiled it into a shared object library but I am unable to link to it (Upon linking, I get undefined reference errors on the lines where I call functions from the library). I found a post on this site that says after adding the /lib directory (where my shared object library lives) to the link directories in CMakeLists, given my lib as libfoo, I add to the CMakeLists file "target_link_libraries(myNode,foo)"

When I do this, I get the following error

CMake Error at CMakeLists.txt:36 (target_link_libraries): Cannot specify link libraries for target "myNode" which is not built by this project.

I am completely stumped. I am pasting my CMakeLists.txt. file just incase it helps. My node is for a diesel generator, called 'dieselGenerator' and my library (for the LabJack) is called libue9.so. It looks like comments get put in bold here, I dont mean to yell. I really appreciate your help.


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)

# Initialize the ROS build system.
rosbuild_init ()

# Set the default path for built executables to the "bin" directory.

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

# Set the name to use for the executable.
set (BINNAME dieselGenerator)

# Set the source files to use with the executable.
#set (SRCS ${SRCS} src/ue9.c)
set (SRCS ${SRCS} src/dieselGenerator.cpp)

# Have ROS autogenerate code used in messages.
rosbuild_genmsg ()

# Set the directories where include files can be found.
include_directories (${PROJECT_SOURCE_DIR}/include)
# Make sure the compiler can find the libraries.
link_directories (${PROJECT_SOURCE_DIR}/lib)
target_link_libraries (dieselGenerator ue9)

# Build the executable that will be used to run this node.
rosbuild_add_executable (${BINNAME} ${SRCS})

# List the libraries here.
set (LIBS ${LIBS} ue9)

Originally posted by Gideon on ROS Answers with karma: 239 on 2011-08-12

Post score: 3


2 Answers 2


Rosanswers logo

In principle your file should work. The only thing is that you need the target (rosbuild_add_executable) before the target_link_libraries.

Originally posted by dornhege with karma: 31395 on 2011-08-12

This answer was ACCEPTED on the original site

Post score: 5


Rosanswers logo

Change the lines with these, and make sure they are in the same order as shown.

rosbuild_add_executable (${BINNAME} ${SRCS})

target_link_libraries(${BINNAME} /pathto/libue9.so)

replace pathto with the full path to your libue9.so library file

give it a try and let me know if it works for u.

Originally posted by Zack with karma: 216 on 2011-08-13

This answer was NOT ACCEPTED on the original site

Post score: 1

Original comments

Comment by Zack on 2011-08-15:
in the target_link_libraries, there should be a space after ${BINNAME} , i've edited the original post to reflect the changes

Comment by dornhege on 2011-08-15:
Can you add your changed CMakeLists.txt file to your original post? The error you listed is from cmake, so before its actually doing things like compiling and linking.

Comment by Gideon on 2011-08-15:
I tried that and it still gave me the same error. I then tried compiling my library using g++. Since my library was written in C I had to make a few changes to get it to compile, but everything seems to be working now. How do you use a library written in C without converting it to C++?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.