0
$\begingroup$

Rosanswers logo

Hi all,

I have been compiling a library and made it ROS compatible - and everything works except that the includes are not copied to the devel/lib/PACKAGE folder.

I have added: include_directories(${catkin_INCLUDE_DIRS} include) and

   DEPENDS pthread
    INCLUDE_DIRS ${catkin_INCLUDE_DIRS} include
    LIBRARIES ${PROJECT_NAME} ...
)

Which according to here should be enough: http://docs.ros.org/api/catkin/html/howto/format2/building_libraries.html

What am I missing to get the includes copied to have them included?

Full CMake files here: https://gitlab.com/korken89/cppViconStream/tree/master

Thanks for all help!

EDIT:

To give a better background to my problem, what problem I am having (and am trying to fix) is that the headers for my library are not found at compile time for the packages dependent on my library. And the catkin looks in the devel/lib/PKG folder for the .so file and the headers, but the headers are not there, hence the previous question.

Am I looking to this problem in the wrong way for using custom libraries as packages?

EDIT2:

As requested, the build logg. Hope it helps!

/home/emifre/Git/ros_ws/devel_ws/src/ros_viconstream/src/ros_viconstream_node.cpp:2:37: fatal error: viconstream/viconstream.h: No such file or directory
compilation terminated.
CMakeFiles/ros_viconstream_node.dir/build.make:62: recipe for target 'CMakeFiles/ros_viconstream_node.dir/src/ros_viconstream_node.cpp.o' failed
make[2]: *** [CMakeFiles/ros_viconstream_node.dir/src/ros_viconstream_node.cpp.o] Error 1
CMakeFiles/Makefile2:539: recipe for target 'CMakeFiles/ros_viconstream_node.dir/all' failed
make[1]: *** [CMakeFiles/ros_viconstream_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
[ros_viconstream] <== '/home/emifre/Git/ros_ws/devel_ws/build/ros_viconstream/build_env.sh /usr/bin/make --jobserver-fds=3,6 -j' failed with return code '2'
                                                                                                                                                                                               
Failed   <== ros_viconstream [ 2.1 seconds ]                                                                                                                                                  
[build] There were '1' errors:                                                                                                                                                                

Failed to build package 'ros_viconstream' because the following command:

# Command to reproduce:
cd /home/emifre/Git/ros_ws/devel_ws/build/ros_viconstream && /home/emifre/Git/ros_ws/devel_ws/build/ros_viconstream/build_env.sh /usr/bin/make --jobserver-fds=3,6 -j; cd -

# Path to log:
cat /home/emifre/Git/ros_ws/devel_ws/build/build_logs/ros_viconstream.log

Exited with return code: 2 

Originally posted by Korken89 on ROS Answers with karma: 15 on 2015-12-20

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I have added: include_directories(${catkin_INCLUDE_DIRS} include) and catkin_package( DEPENDS pthread INCLUDE_DIRS ${catkin_INCLUDE_DIRS} include LIBRARIES ${PROJECT_NAME} ... )

Which according to here should be enough: http://docs.ros.org/api/catkin/html/h...

The page you refer to also mentions all the CMake install rules you have to add for files to be installed to the correct locations. Only auto-generated headers (like those from the various msg code generators) get their install targets automatically added.

See the Installing section of the Building and installing C++ libraries and headers page you linked.

Could you indicate which text on that page gave the impression that no install rules were necessary for the headers to be installed?


Edit: I misunderstood your question.

I have been compiling a library and made it ROS compatible - and everything works except that the includes are not copied to the devel/lib/PACKAGE folder.

Headers are never copied to devel/lib/PKG. Afaik the only headers to be present in the devel space are the ones auto-generated by gencpp and friends, and those would go into devel/include/PKG. If you're not installing, catkin will set up the include paths such that they point to the src/PKG/include/.. directories, which avoids the need to copy files around. Only an install space will have pkg headers in install/include/PKG, but then only if the necessary install statements have been added to the CMakeLists.txt.

As to your actual issue: please describe it more clearly. Are you getting errors telling you that headers cannot be found at compile time?


Edit2: first:

And the catkin looks in the devel/lib/PKG folder for the .so file and the headers, but the headers are not there, hence the previous question.

catkin doesn't look for headers in devel/lib/PKG, in fact, it doesn't look for anything, it is a build tool. The compiler may look in devel/lib/PKG, but only if you made CMake (underlying catkin) add that path to the include_directories(..).

/home/emifre/Git/ros_ws/devel_ws/src/ros_viconstream/src/ros_viconstream_node.cpp:2:37: fatal error: viconstream/viconstream.h: No such file or directory
compilation terminated.

From this error message, it seems the compiler is looking for the viconstream.h file in a directory named viconstream, which should be on the include path. Your CMakeLists.txt adds only the include directory, but there is no include/viconstream sub dir, so the compiler will never be able to find that file, no matter how you configure the include path.

Possible solutions:

  1. change #include <viconstream/viconstream.h> to #include <viconstream.h>
  2. create a sub directory viconstream in your pkg's include directory and place viconstream.h in it

I recommend option 2.

PS: this has actually nothing to do with catkin, nor CMake. Using any other build tool (or even writing Makefiles by hand) would have resulted in exactly the same error.


Originally posted by gvdhoorn with karma: 86574 on 2015-12-21

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Korken89 on 2015-12-21:
I have this impression as I am not trying to install, just compiling the package for local use to my workspace. As I understood it, which might not be correct, is the install is only used when installing to the ROS libraries for permanent usage. Am I completely of here?

Comment by Korken89 on 2015-12-21:
I have updated the original question to describe the background problem. Thanks for the help!

Comment by Korken89 on 2015-12-21:
I have added the error log. Hope it helps!

Comment by Korken89 on 2015-12-22:
Thank you for explaining that! I am mostly only using CMake by itself and not with catkin as a build system, so the internal workings of the system is under learning. :) Thanks again for clearing this for me!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.