how to include catkin package ?
suppose i have directory tree like this :
.
├── .catkin_tools
│ ├── CATKIN_IGNORE
│ ├── profiles
│ │ └── default
│ ├── README
│ └── VERSION
└── src
├── pkg_a
│ ├── CMakeLists.txt
│ ├── mutiply.cpp
│ ├── package.xml
│ └── sumfunc.cpp
└── pkg_b
├── CMakeLists.txt
├── main.cpp
└── package.xml
6 directories, 10 files
how can i edit CMakeLists.txt So that i can use those file in pkg_a inside pkg_b/main.cpp like this :
#include <pkg_a/mutiply.cpp>
#include <pkg_a/sumfunc.cpp>
#include <pkg_a/someheader.h>// or maybe this one
int main(void) {
int sum_result = sum(5,5);
int muli_result = muti(5,5);
return 0;
}
NOTE : i already take a look at this recommend but i not quite understand it.
Edit :
after @Weasfas Answer i have create func_terminal.h file in pkg_a and have this tree file :
└── src
├── pkg_a
│ ├── CMakeLists.txt
│ ├── func_terminal.h
│ ├── mutiply.cpp
│ ├── package.xml
│ └── sumfunc.cpp
└── pkg_b
├── CMakeLists.txt
├── main.cpp
└── package.xml
and add some command in cmakeList.txt in pkg_b : add find package
find_package(catkin REQUIRED COMPONENTS roscpp pkg_a)
add include_directories
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add catkin package
catkin_package(
CATKIN_DEPENDS pkg_a
)
and in building
add_executable(main_node main.cpp)
target_link_libraries(main_node ${catkin_LIBRARIES})
add_dependencies(main_node ${catkin_EXPORTED_TARGETS})
then edit package.xml by add these line
<build_depend>pkg_a</build_depend>
<build_export_depend>pkg_a</build_export_depend>
<exec_depend>pkg_a</exec_depend>
but i will get an error
fatal error: pkg_a/func_terminal.h: No such file or directory
from catkin build if i try to add this line #include <pkg_a/func_terminal.h>
in pkg_b/main.cpp file
Edit #2(RECAP):
I'll explain the solution i have got thank to @Weasfas steb by steb here : first i need to create a proper catkin_work_space for example in my case i use these command :
mkdir tryCatkin && mkdir tryCatkin/src && cd tryCatkin && catkin_make
then i can either use catkin_create_pkg
command or just create out of of nowhere by following catkin package format which will create directory tree like this:
├── src
│ ├── CMakeLists.txt -> /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
│ ├── pkg_a
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ │ └── pkg_a
│ │ │ └── fuction_terminal.hpp
│ │ ├── package.xml
│ │ └── src
│ │ └── function_terminal.cpp
│ └── pkg_b
│ ├── CMakeLists.txt
│ ├── include
│ │ └── pkg_b
│ ├── package.xml
│ └── src
│ └── main.cpp
in pkg_b/src/main.cpp :
#include <iostream>
#include <pkg_a/fuction_terminal.hpp>
int main(void) {
int sum_result = sumation(5,5); ///sumation is function in func_terminal.hpp
std::cout << "test : " << sum_result;
return 0;
}
then setup those package.xml and CmakeList.txt which i follow from @Weasfas instruction. first in pkg_a/Cmakelist.txt :
cmake_minimum_required(VERSION 2.8.3)
project(pkg_a)
find_package(catkin REQUIRED COMPONENTS)
catkin_package(
INCLUDE_DIRS include
LIBRARIES SumFunc
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_library(SumFunc
src/function_terminal.cpp
)
pkg_b/CmakeList.txt :
cmake_minimum_required(VERSION 2.8.3)
project(pkg_b)
find_package(catkin REQUIRED COMPONENTS
pkg_a
)
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
add_executable(main_node src/main.cpp)
target_link_libraries(main_node
${catkin_LIBRARIES}
)
and then in pkg_b/package.xml add this line:
<depend>pkg_a</depend>