CMake error trying to link target to libraries
Dear All, I am using Ubuntu 14.04 and ROS Indigo.
I have created a pkg named "joy" in which there are two source file named joystick.cpp
and js_info.cpp
under joy/src
folder. also i have header file joystick.h
under include/joy
folder.
i have compiled that 3 files and they work correctly.
But when i placed this files as told you above, gives me error as shown below:
CMake Error at joy/CMakeLists.txt:61 (target_link_libraries):
Target "joystick" of type EXECUTABLE may not be linked into another target.
One may link only to STATIC or SHARED libraries, or to executables with the
ENABLE_EXPORTS property set.
-- Configuring incomplete, errors occurred!
See also "/home/darshan/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/darshan/catkin_ws/build/CMakeFiles/CMakeError.log".
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
This below shown is my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.3)
project(joy)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS roscpp rospy std_msgs
)
include_directories(include
${catkin_INCLUDE_DIRS}
)
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)
Please provide me the solution. I would be thankful to all of you.
Edit: Thank you so much for quick and prompt reply.
But if i change that line to
target_link_libraries(js_info ${catkin_LIBRARIES} )
like this. I get the following error.
darshan@darshan-Inspiron-N4010:~/catkin_ws$ catkin_make
Base path: /home/darshan/catkin_ws
Source space: /home/darshan/catkin_ws/src
Build space: /home/darshan/catkin_ws/build
Devel space: /home/darshan/catkin_ws/devel
Install space: /home/darshan/catkin_ws/install
####
#### Running command: "make cmake_check_build_system" in "/home/darshan/catkin_ws/build"
####
####
#### Running command: "make -j4 -l4" in "/home/darshan/catkin_ws/build"
####
[ 0%] Built target _rosserial_arduino_generate_messages_check_deps_Test
[ 0%] [ 0%] [ 0%] Built target _rosserial_msgs_generate_messages_check_deps_RequestParam
Built target _rosserial_msgs_generate_messages_check_deps_RequestServiceInfo
Built target _rosserial_arduino_generate_messages_check_deps_Adc
[ 0%] Built target _rosserial_msgs_generate_messages_check_deps_Log
[ 0%] Built target _rosserial_msgs_generate_messages_check_deps_TopicInfo
[ 0%] Built target _rosserial_msgs_generate_messages_check_deps_RequestMessageInfo
[ 0%] Built target std_msgs_generate_messages_py
[ 13%] Built target abc
[ 13%] Built target _beginner_tutorials_generate_messages_check_deps_Num
[ 13%] Built target std_msgs_generate_messages_lisp
[ 13%] Built target _beginner_tutorials_generate_messages_check_deps_AddTwoInts
[ 13%] Built target std_msgs_generate_messages_cpp
[ 15%] Built target hello
Linking CXX executable /home/darshan/catkin_ws/devel/lib/joy/joystick
[ 28%] Built target gui_ros
Linking CXX executable /home/darshan/catkin_ws/devel/lib/joy/js_info
[ 30%] Built target hello_world
[ 43%] Built target example
[ 46%] Built target rosserial_arduino_generate_messages_lisp
[ 47%] Built target turtle_teleop_joy
[ 53%] Built target rosserial_arduino_generate_messages_py
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug ...
May I suggest to change the title of your question? It has nothing to do with header files. Perhaps something like "CMake error trying to link target to libraries" is more appropriate.
Also, a ROS package with the name joy already exists. This will cause problems if you need both packages at the same time.
http://wiki.ros.org/joy
Please do not post answers to provide us with more information, update your question description for that, using the edit link/button below it. I've moved the contents of your answer this time.