Revision history [back]

The error you get is actually quite clear, especially when you look at the following snippet from your CMakeLists.txt:

add_executable(joystick src/joystick.cpp)
target_link_libraries(joystick ${catkin_LIBRARIES}) add_executable(js_info src/js_info.cpp) target_link_libraries(js_info${catkin_LIBRARIES} joystick)


You are trying to link js_info against catkin_LIBRARIES (good) and against joystick (not good). That can't work: joystick is an executable, you just declared it 4 lines earlier with add_executable(joystick src/joystick.cpp). You cannot link two executables together.

The error you get is actually quite clear, especially when you look at the following snippet from your CMakeLists.txt:

add_executable(joystick src/joystick.cpp)
target_link_libraries(joystick ${catkin_LIBRARIES}) add_executable(js_info src/js_info.cpp) target_link_libraries(js_info${catkin_LIBRARIES} joystick)


You are trying to link js_info against catkin_LIBRARIES (good) and against joystick (not good). That can't work: joystick is an executable, you just declared it 4 lines earlier with add_executable(joystick src/joystick.cpp). You cannot link two executables together.

Also: this is really not ROS related, it's basic CMake and building of executables / binaries.

The error you get is actually quite clear, especially when you look at the following snippet from your CMakeLists.txt:

add_executable(joystick src/joystick.cpp)
target_link_libraries(joystick ${catkin_LIBRARIES}) add_executable(js_info src/js_info.cpp) target_link_libraries(js_info${catkin_LIBRARIES} joystick)


You are trying to link js_info against catkin_LIBRARIES (good) and against joystick (not good). That can't work: joystick is an executable, you just declared it 4 lines earlier with add_executable(joystick src/joystick.cpp). You cannot link two executables together.

Also: this is really not ROS related, it's basic CMake and building of executables / binaries.

Edit:

[..] if i change that line to

target_link_libraries(js_info \${catkin_LIBRARIES} )


like this. I get the following error:

[..]
CMakeFiles/js_info.dir/src/js_info.cpp.o: In function main':
js_info.cpp:(.text+0x7a): undefined reference to Joystick::Joystick(char const*)'
js_info.cpp:(.text+0x204): undefined reference to Joystick::getName()'
js_info.cpp:(.text+0x234): undefined reference to Joystick::numAxes()'
[..]


This seems to indicate that the js_info target requires symbols from joystick.cpp. You could either:

• make the joystick target a library (add_library(..) instead of add_executable(..)) and link js_info against that, or
• add joystick.cpp to the list of source files for the js_info target