# How to include header file from different workspace?

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")

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 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.

( 2018-01-16 09:08:33 -0500 )edit

Sort by » oldest newest most voted

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}
more