# cannot specify link libraries for target

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 close merge delete

Sort by » oldest newest most voted

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

more

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

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.

more

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.
( 2011-08-12 13:52:14 -0600 )edit

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)

rosbuild_add_executable (${BINNAME}${SRCS})

set (LIBS \${LIBS} ue9)

more

You can use <pre> tags to fix that. For source code 4 space indendation will highlight that properly.
( 2011-08-12 08:46:38 -0600 )edit
( 2011-08-12 11:13:16 -0600 )edit
Thanks, I think I shot my self in the foot as the thread seems answered. I will use the edit function next time.
( 2011-08-12 11:57:58 -0600 )edit