How to fix circular dependency in catkin libraries?

asked 2020-10-07 11:57:10 -0500

Paal gravatar image


I've currently run into the issue where I try to add two c++ libraries to my catkin_ws but the libraries somewhat depend on each other. The dependency is as follows

  • Library_A needs to extract class definitions declared in some of Library_B's headers, that is one header file in Library_A includes a header file from Library_B in order to access its class definition.
  • Library_B is build dependent on Library_A, that is Library, that is some of the cpp files in Library_B includes header files from Library_A in order to interface with its functions.

How should I structure my CMakeLists.txt and package.xml in order to achieve a proper build?

edit retag flag offensive close merge delete


Circular dependencies are a pain. You should avoid having them in the first place. If possible, create a package C that ships the parts that need to be included in one of the libraries and thus break the circular dependency. If this is not possible, you should reconsider your whole architecture. If you need more help, you need to show concrete examples (directory structure, which file includes which, CMakeLists.txt).

mgruhler gravatar image mgruhler  ( 2020-10-09 02:37:37 -0500 )edit

Agree with mgruhler

Aakashp gravatar image Aakashp  ( 2020-10-26 07:42:37 -0500 )edit