Kyuhwan Yeon
Kyuhwan Yeon

Reputation: 161

Cmake package configuration when looking for each other's packages

When i catkin_make when module_one find package module_two and module_two find package module_one, there is error like below

-- +++ processing catkin package: 'module_one'
-- ==> add_subdirectory(module_one)
-- Could NOT find module_two (missing: module_two_DIR)
-- Could not find the required component 'module_two'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "module_two" with
  any of the following names:

    module_twoConfig.cmake
    module_two-config.cmake

  Add the installation prefix of "module_two" to CMAKE_PREFIX_PATH or set
  "module_two_DIR" to a directory containing one of the above files.  If
  "module_two" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  module_one/CMakeLists.txt:10 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/ri/workspace/catkin_playground/build/CMakeFiles/CMakeOutput.log".
See also "/home/ri/workspace/catkin_playground/build/CMakeFiles/CMakeError.log".

the workspace folder tree is below

├── build
│   ├── atomic_configure
│   ├── catkin
│   │   └── catkin_generated
│   │       └── version
│   ├── catkin_generated
│   │   ├── installspace
│   │   └── stamps
│   │       └── Project
│   ├── CMakeFiles
│   │   ├── 3.11.0
│   │   │   ├── CompilerIdC
│   │   │   │   └── tmp
│   │   │   └── CompilerIdCXX
│   │   │       └── tmp
│   │   └── CMakeTmp
│   ├── gtest
│   │   ├── CMakeFiles
│   │   └── googlemock
│   │       ├── CMakeFiles
│   │       └── gtest
│   │           └── CMakeFiles
│   ├── module_one
│   │   └── CMakeFiles
│   └── test_results
├── devel
│   └── lib
└── src
    ├── module_one
    └── module_two

module_one's CMakeLists.txt has

find_package(catkin REQUIRED module_two)

module_two's CMakeLists.txt has

find_package(catkin REQUIRED module_one)

like above project,
Is there a CMakeLists configuration for referencing packages to each other?

Upvotes: 1

Views: 1483

Answers (1)

JWCS
JWCS

Reputation: 1201

I tried to imitate your setup: I made a new workspace, I make two new packages using catkin_create_pkg, and I got your error. This happens when some of the following setup issues aren't addressed:

  • In CMakeLists.txt, you must find_package(catkin REQUIRED COMPONENTS ...) the neccessary packages (don't forget roscpp if you use C++!)
# In module_1
find_package(catkin REQUIRED COMPONENTS
  roscpp
  module_2
)
  • In CMakeLists.txt, you must declare to catkin your dependencies as well (this CATKIN_DEPENDS list is a mirror of the find_package list above):
# In module_1
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES mod2
  CATKIN_DEPENDS roscpp module_2
#  DEPENDS system_lib
)
  • In package.xml you need a <depend> for that module as well.
<!-- In module_1 -->
<depend>module_2</depend>

If you do all that, then that error goes away. But then you have a new error:

Circular dependency in subset of packages: module_1, module_2

I would recommend you re-structure your code to avoid circular dependencies, either by combining packages, or if you prefer tiny packages, pulling out the common dependencies to a third package.

Upvotes: 1

Related Questions