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

How to include header file from different workspace?

asked 2018-01-16 03:21:16 -0500

Kiwi gravatar image

Hey, I am new to ROS and its my first post, so I hope everything is understandable.

I am trying to include a header file in the package (B) from a different package (A) which is in a different workspace. I can include messages from the package. I overlayed the workspace and added the the packge in the CMakeLsts.txt

find_package(catkin REQUIRED COMPONENTS
A
)

catkin_package(
CATKIN_DEPENDS
A
)

install (DIRECTORY include/${A}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h")

add_library(library A/src/AClass.cpp)

add_executable(ClassIncludeAClass  src/ClassIncludeAClass.cpp)
target_link_libraries(ClassIncludeAClass   ${catkin_LIBRARIES} library )

ClassIncludeAClass .cpp

#include "A/AClass.h"

When I include the whole path to the file the Compiler has undefined references to functions of the class AClass.

I found the following question https://answers.ros.org/question/2019... to include a header form the same Workspace but a different package.

Thanks in advance for any help!

edit retag flag offensive close merge delete

Comments

I think you are missing this: include_directories(${catkin_INCLUDE_DIRS}) which will tell the compiler to look for include files also in the include folders of the packaged that you found in find_package.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2018-01-16 09:08:33 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-01-16 06:25:42 -0500

mgruhler gravatar image

I'm assuming this is the CMakeLists.txt of package B.

Thus, the install(.. part makes no sense. Why would you want to install something from INSIDE package B? Do you have a layout like B/include/A? Also, what do you expect ${A} do contain? This variable should not be set anywhere in here.

The same holds for the add_library call. Why do you, in package B want to build a package in A.

The answer you cite is correct, so please follow this.

  • In pkg A:
    • compile the library
    • install the library and Header files of pkg A (actually, not even required)
    • Export the include path and the library with the catkin_package call (check out the template when you create a new package)
  • In pkg B:
    • set up the build_depend to pkg A
    • find_package package A
    • add include_directories(${catkin_INCLUDE_DIRS})
    • include the Header in your package B code
    • link against the ${catkin_LIBRARIES}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2018-01-16 03:21:16 -0500

Seen: 1,312 times

Last updated: Jan 16 '18