1

I am compiling a 3rd party library which uses the following commands to find Eigen3:

find_package( PkgConfig )
pkg_check_modules( EIGEN3 REQUIRED eigen3 )
include_directories(${EIGEN3_INCLUDE_DIRS})

The find_package( PkgConfig ) command runs correctly because I specified the PKG_CONFIG_EXECUTABLE variable. But pkg_check_modules( EIGEN3 REQUIRED eigen3 ) returns an error:

-- Checking for module 'eigen3'

-- No package 'eigen3' found

The Eigen3's official webpage says "It is not necessary to use CMake or install anything." It took me quite a while to realize this statement is wrong. So I ran the following to compile and install Eigen3 (version 3.3.5):

cmake -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_INSTALL_PREFIX=E:\3rd-parties\eigen-3.3.5\install_ -G"Visual Studio 14 2015 Win64" ..

The compilation and installation process were both successful because I didn't see any failure in VS2015. But, when I go back to the build folder of the 3rd party library and run cmake again, I got exactly the same error. Eigen3 official website only provides an instruction using find_package, but not pkg-config.exe, so I next searched Google and find this thread. The answer says we need to "enable pkg-config support in the eigen3 cmake". I don't know how to enable it. Is there any specific CMake variable for this purpose? Since it is a new problem, and Eigen's main page says "To get help, stackoverflow is your best resource." so I come here for help. My question is: how to enable pkg-config support in eigen3? Or to put it another way: how to pass the pkg_check_modules( EIGEN3 REQUIRED eigen3 ) cmake command? Thanks a lot.

PS: I am working on Windows 10.

Community
  • 1
  • 1
user5280911
  • 723
  • 1
  • 8
  • 21

1 Answers1

3

According to the Eigen3 sources, an option EIGEN_BUILD_PKGCONFIG is responsible on pkg-config support.

On Windows the whole option is disabled, but you may try to set it:

cmake -DEIGEN_BUILD_PKGCONFIG=ON <... other arguments>

When use pkg-config for find Eigen3 in CMake script, make sure that installation directory of Eigen3 is listed in CMAKE_PREFIX_PATH variable. (If CMake version used by a project is less than 3.1, then you need to additionally set PKG_CONFIG_USE_CMAKE_PREFIX_PATH to ON for tell pkgconfig module to use variable CMAKE_PREFIX_PATH. See more in the documentation for pkgconfig module.)

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Thank you for the reply. I added the `EIGEN_BUILD_PKGCONFIG` option when building Eigen3 and it works on Windows. A new folder `E:\3rd-parties\eigen-3.3.5\install_\share\pkgconfig` is created and a file `eigen3.pc` is in it. But `pkg-config.exe` is still unable to find Eigen3 after I tried various values for `CMAKE_PREFIX_PATH`. Could you please give me one more help about how to instruct `pkg-config` to locate where Eigen3 installation is? Thanks a lot. – user5280911 Dec 02 '18 at 22:02
  • Hm, passing option `-DCMAKE_PREFIX_PATH=E:/3rd-parties/eigen-3.3.5/install_` to `cmake` (or corresponding setting in CMake GUI) should work. – Tsyvarev Dec 02 '18 at 22:45
  • Sorry, it doesn't work. The document of CMAKE_PREFIX_PATH says it supports find_package(), find_program(), find_library(), find_file(), and find_path(). Does it mean CMAKE_PREFIX_PATH only work with these functions, but not with pkg_check_modules()? – user5280911 Dec 03 '18 at 00:08
  • I was gussing right, pkg_check_modules uses FindPkgConfig(), while CMAKE_PREFIX_PATH works only with find_package(), find_program(), find_library(), find_file(), and find_path(). There is a variable in FindPkgConfig() that controls whether it uses CMAKE_PREFIX_PATH -- PKG_CONFIG_USE_CMAKE_PREFIX_PATH. It is enabled by default if the minimum CMake version is >= 3.1, but the 3rd-party library I am compiling happens to set it to 2.8 ..... I have edited your answer to include this trick. – user5280911 Dec 03 '18 at 01:46
  • I have rephrased you edit to a simpler form, which notes about specific of low version of CMake. – Tsyvarev Dec 03 '18 at 08:10