0

I've implemented a library which uses Eigen3. The following lines are part of the CMake of this library:

#EIGEN
find_package(Eigen3 REQUIRED) 
include_directories(${EIGEN3_INCLUDE_DIR})

And Eigen3 is found and my library compiles without any problem.

The complication appears when I use my library in other project. This project has nothing to be with Eigen, it is not used there. However, if I don't include the Eigen include dirs in this project as well, its compilation fails.

My library is compiled as a dynamic one, and I guess some Eigen stuff is missing from it, and that's why the project needs Eigen include directories as well. Any idea about how to fix this?

Thank you.

PS: I'm in Ubuntu 13.04 and using QtCreator as IDE.

jotaraul
  • 21
  • 4
  • Why not ask this on http://answers.ros.org? – BenC May 07 '14 at 09:34
  • @BenC Why ask this on ros? – luk32 May 07 '14 at 09:40
  • @luk32 because he said (before editing) that the problem appears when he's using ROS, and ROS uses a dedicated system based on CMake (catkin). – BenC May 07 '14 at 09:42
  • @BenC I just see no information about it. I am very curious, did you deduce it from the behaviour? That would be really nice! – luk32 May 07 '14 at 09:43
  • Sorry for the editing. The initial problem was with a ROS node (in fact using ROS-Build and not Catkin), but the same holds for any project that uses my library. Thanks for your answers :) – jotaraul May 07 '14 at 09:46
  • @luk32 don't worry, no jedi mind trick was involved ;-) – BenC May 07 '14 at 09:54
  • @jotaraul the pkg-config way I put in my answer works with rosbuild as well, although you should definitely consider moving to catkin at some point (the transition is a matter of minutes really). – BenC May 07 '14 at 09:55

3 Answers3

2

Eigen is a header only library (save for some blas bindings). The only way to make sure Eigen isn't required as a build time dependency when your library is used is to only include Eigen headers in your library's source files, and none in your headers. This may require some wrapping of Eigen types and functions with PIMPL or some such.

If this is the case already, your question is missing information.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
0

As @rubenvb said, Eigen is header only. However, you may want to provide some template functions as well, and in this case, you need to add Eigen to the other project's include directories. Moreover, you may have other dependencies at some point that simply cannot be hidden as @rubenvb advised. But don't worry! For a CMake project, if you generate a pkg-config file for your library, you can simply use:

find_package(PkgConfig)
pkg_check_modules(YourLib REQUIRED yourlib)
include_directories(${YourLib_INCLUDE_DIRS})

This would thus be transparent for the user. Any other dependencies would also be treated simultaneously. Note that libraries and definitions are also available. This is all explained in the CMake documentation of pkg_check_modules.

In the special case of ROS nodes (which you asked before editing), these includes can also be done automatically with catkin, when you state that your library is a dependency of the ROS node. For more information, check the catkin documentation.

BenC
  • 8,729
  • 3
  • 49
  • 68
0

If you include Eigen headers in your headers, then Eigen is a public dependency of your project.

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html

See also

http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html

(although Eigen doesn't create IMPORTED targets as yet).

steveire
  • 10,694
  • 1
  • 37
  • 48