ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
3

cannot specify link libraries for target

asked 2011-08-12 08:20:41 -0500

Gideon gravatar image

updated 2011-08-12 08:45:40 -0500

dornhege gravatar image

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.

Cheers

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


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

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2011-08-12 08:51:23 -0500

dornhege gravatar image

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

edit flag offensive delete link more
1

answered 2011-08-13 05:14:18 -0500

Zack gravatar image

updated 2011-08-15 16:06:56 -0500

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.

edit flag offensive delete link more

Comments

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++?
Gideon gravatar image Gideon  ( 2011-08-15 05:51:34 -0500 )edit
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.
dornhege gravatar image dornhege  ( 2011-08-15 10:32:01 -0500 )edit
in the target_link_libraries, there should be a space after ${BINNAME} , i've edited the original post to reflect the changes
Zack gravatar image Zack  ( 2011-08-15 16:06:39 -0500 )edit
0

answered 2011-08-12 09:21:15 -0500

Gideon gravatar image

Well, that fixed the error "Cannot specify link libraries for target "myNode" which is not built by this project."

But now I am back to getting an undefined reference error

Linking CXX executable ../bin/dieselGenerator CMakeFiles/dieselGenerator.dir/src/dieselGenerator.o: In function DieselGenerator::Init()': /home/ubuntu/GA_UUV/uuv/dieselGenerator/src/dieselGenerator.cpp:60: undefined reference toopenTCPConnection(char*, int)'

I have checked the obvious stuff (I am spelling it right, etc.. ). Any other ideas why I cant link to the library?

Thanks again.

edit flag offensive delete link more

Comments

This seems like a different problem than the original. Where is toopenTCPConnection(char*, int)' defined? Is it in the library - then verify that is linked with VERBOSE=1 make.
dornhege gravatar image dornhege  ( 2011-08-12 13:52:14 -0500 )edit
-1

answered 2011-08-12 08:28:12 -0500

Gideon gravatar image

The formatting on the CMakeLists.txt file looks awful. I have removed the comments so it is easier to read.

cmake_minimum_required (VERSION 2.4.6) include ($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init ()

set (EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

set (BINNAME dieselGenerator)

set (SRCS ${SRCS} src/dieselGenerator.cpp)

rosbuild_genmsg ()

include_directories (${PROJECT_SOURCE_DIR}/include)

link_directories (${PROJECT_SOURCE_DIR}/lib)

target_link_libraries (dieselGenerator ue9)

rosbuild_add_executable (${BINNAME} ${SRCS})

set (LIBS ${LIBS} ue9)

edit flag offensive delete link more

Comments

You can use <pre> tags to fix that. For source code 4 space indendation will highlight that properly.
dornhege gravatar image dornhege  ( 2011-08-12 08:46:38 -0500 )edit
@Gideon Please use the edit function instead of providing an "answer" which is more of your question.
tfoote gravatar image tfoote  ( 2011-08-12 11:13:16 -0500 )edit
Thanks, I think I shot my self in the foot as the thread seems answered. I will use the edit function next time.
Gideon gravatar image Gideon  ( 2011-08-12 11:57:58 -0500 )edit

Question Tools

Stats

Asked: 2011-08-12 08:20:41 -0500

Seen: 21,951 times

Last updated: Aug 15 '11