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

Catkin not finding Header Files

asked 2016-04-17 01:47:04 -0500

Tardoe gravatar image

Hi all, i'm pulling my hair out trying to get my project to compile. I'm using some third party header files which I have copied to /home/pi/ros_catkin_ws/src/eyebot_testing/include/eyebot_testing, the parent header file is eyebot.h which then includes all others.

In my node file (~/ros_catkin_ws/src/eyebot_testing/src/eyebot_testing_node.cpp) I have this:

#include "ros/ros.h"
#include "eyebot_testing/eyebot.h"

int main()
{
    MOTORDriveRaw(1, 0);
    return 0;
}

And my CMakeList.txt file has the following:

cmake_minimum_required(VERSION 2.8.3)
project(eyebot_testing)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  CATKIN_DEPENDS roscpp rospy std_msgs
)

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

link_directories(/home/pi/eyebot/lib)

## Declare a C++ library
#add_library(eyebot_testing
#   src/${PROJECT_NAME}/eyebot_testing.cpp
# )


## Declare a C++ executable
add_executable(eyebot_testing_node src/eyebot_testing_node.cpp)

## Specify libraries to link a library or executable target against
find_library(eyebot_testing_node /home/pi/eyebot/lib/)

target_link_libraries(eyebot_testing_node
   ${catkin_LIBRARIES}
   wiringPi
   mpsse
   X11
   lirc_client
   m
   opencv_core
   opencv_highgui
   opencv_imgproc
   eyebot
 )

## Mark cpp header files for installation
install(
   DIRECTORY include/${PROJECT_NAME}/
   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
 )

This is the command i'm using to just compile my package:

cd /home/pi/ros_catkin_ws/build_isolated/eyebot_testing && sudo /home/pi/ros_catkin_ws/install_isolated/env.sh make VERBOSE=3 -j4 -l4BC

The verbose mode show the include directories ( -I ) are being added in an earlier step and the Library i'm using is being linked in the later step, however i'm still getting a method not found error:

pi@rospi:~/ros_catkin_ws/src/eyebot_testing $ cd /home/pi/ros_catkin_ws/build_isolated/eyebot_testing && sudo /home/pi/ros_catkin_ws/install_isolated/env.sh make VERBOSE=3 -j4 -l4BC
/usr/bin/cmake -H/home/pi/ros_catkin_ws/src/eyebot_testing -B/home/pi/ros_catkin_ws/build_isolated/eyebot_testing --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/pi/ros_catkin_ws/build_isolated/eyebot_testing/CMakeFiles /home/pi/ros_catkin_ws/build_isolated/eyebot_testing/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/pi/ros_catkin_ws/build_isolated/eyebot_testing'
make -f CMakeFiles/eyebot_testing_node.dir/build.make CMakeFiles/eyebot_testing_node.dir/depend
make[2]: Entering directory '/home/pi/ros_catkin_ws/build_isolated/eyebot_testing'
cd /home/pi/ros_catkin_ws/build_isolated/eyebot_testing && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/pi/ros_catkin_ws/src/eyebot_testing /home/pi/ros_catkin_ws/src/eyebot_testing /home/pi/ros_catkin_ws/build_isolated/eyebot_testing /home/pi/ros_catkin_ws/build_isolated/eyebot_testing /home/pi/ros_catkin_ws/build_isolated/eyebot_testing/CMakeFiles/eyebot_testing_node.dir/DependInfo.cmake --color=
Dependee "/home/pi/ros_catkin_ws/src/eyebot_testing/include/eyebot_testing/eyebot.h" is newer than depender "CMakeFiles/eyebot_testing_node.dir/src/eyebot_testing_node.cpp.o".
Clearing dependencies in "/home/pi/ros_catkin_ws/build_isolated/eyebot_testing/CMakeFiles/eyebot_testing_node.dir/depend.make".
Scanning dependencies of target eyebot_testing_node
make[2]: Leaving directory '/home/pi/ros_catkin_ws/build_isolated/eyebot_testing'
make -f CMakeFiles/eyebot_testing_node.dir/build.make CMakeFiles/eyebot_testing_node.dir/build
make[2]: Entering directory '/home/pi/ros_catkin_ws/build_isolated/eyebot_testing'
/usr/bin/cmake -E cmake_progress_report /home/pi/ros_catkin_ws/build_isolated/eyebot_testing/CMakeFiles 1
[100%] Building CXX object CMakeFiles/eyebot_testing_node.dir/src/eyebot_testing_node.cpp.o
/usr/bin/c++   -DROSCONSOLE_BACKEND_LOG4CXX -DROS_PACKAGE_NAME=\"eyebot_testing\" -I/home/pi/ros_catkin_ws/src/eyebot_testing/include ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-17 01:54:33 -0500

gvdhoorn gravatar image

updated 2016-04-18 05:29:33 -0500

CMakeFiles/eyebot_testing_node.dir/src/eyebot_testing_node.cpp.o: In function `main':
eyebot_testing_node.cpp:(.text+0x10): undefined reference to `MOTORDriveRaw(int, int)'
collect2: error: ld returned 1 exit status

An undefined reference error is a linking problem, it's not a problem with headers (compilation has already completed).


Edit:

So I've got this now:

add_library(eyebot STATIC IMPORTED)
SET_TARGET_PROPERTIES(eyebot PROPERTIES IMPORTED_LOCATION /home/pi/eyebot/lib/libeyebot.a)

target_link_libraries(eyebot_testing_node
   ${catkin_LIBRARIES}
    ... some other
   eyebot )

Still the same linker error.

Is this a c library that you are trying to link against? If yes: please surround the #include <..> for the header with extern "C" { .. }. This is probably a name mangling issue then. You can leave the import bits in the CMakeLists.txt.

See using an external library: C versus C++ issue for more info.

edit flag offensive delete link more

Comments

Ah okay.

In that case, i'm linking against library "libeyebot.so" - what am I missing is the library is located in the /home/pi/eyebot/lib directory specified in link_directories(/home/pi/eyebot/lib).

Thanks for the fast response!

Tardoe gravatar image Tardoe  ( 2016-04-17 21:10:33 -0500 )edit

I don't really follow: did you get it to work, or are you asking why it doesn't link?

gvdhoorn gravatar image gvdhoorn  ( 2016-04-18 01:48:28 -0500 )edit

I'm asking why it's not linking correctly because I have libeyebot.a in the /home/pi/eyebot/lib folder which i'm using link_directories() to and then including "eyebot" in the target_link_libraries() link. I've tried specifying just "eyebot" as well as "libeyebot.a".

Tardoe gravatar image Tardoe  ( 2016-04-18 03:14:26 -0500 )edit

I think you're running into a peculiarity of CMake and how it handles static libraries it didn't built itself (it actually makes sense, but that is out of scope). See this post for a recipe to do what you want.

gvdhoorn gravatar image gvdhoorn  ( 2016-04-18 03:30:22 -0500 )edit

Also: please try to avoid hard coding paths to libraries and includes in your build scripts. It makes them brittle and can lead to hard to debug errors.

Also2: it's often better to work with absolute paths to libraries in CMake instead of using link_directories().

gvdhoorn gravatar image gvdhoorn  ( 2016-04-18 03:31:46 -0500 )edit

See also CMake - Tutorials - Exporting and Importing Targets on the CMake wiki for more info on importing targets.

gvdhoorn gravatar image gvdhoorn  ( 2016-04-18 03:34:05 -0500 )edit

So I've got this now: add_library(eyebot STATIC IMPORTED) SET_TARGET_PROPERTIES(eyebot PROPERTIES IMPORTED_LOCATION /home/pi/eyebot/lib/libeyebot.a)

target_link_libraries(eyebot_testing_node ${catkin_LIBRARIES} ... some other eyebot )

Still the same linker error.

Tardoe gravatar image Tardoe  ( 2016-04-18 04:02:36 -0500 )edit

Excellent!!! Thats gone and done it :D

Thank you so much!

Tardoe gravatar image Tardoe  ( 2016-04-18 05:10:58 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-17 01:47:04 -0500

Seen: 1,936 times

Last updated: Apr 18 '16