Using ITK + Eigen

Hello,

I am trying to use ITK with an external Eigen build.
ITK was installed first in our server by the system analyst. Then I asked him if he could install Eigen.

I am making an application that uses ITK for reading and processing images and I need Eigen to compute some linear algebra stuff. However when I try to link Eigen libraries I get an error message.

This is the error message I get when I try to build the project. It seems it is looking for itkeigen…

/usr/local/include/eigen3/Eigen/src/Core/StlIterators.h:410:46: note: no functions named ‘typename Eigen::DenseBase<Derived>::iterator Eigen::DenseBase<Derived>::begin()’
In file included from /usr/local/include/ITK-5.2/itkeigen/Eigen/Core:440,
                 from /usr/local/include/ITK-5.2/itkeigen/Eigen/Eigenvalues:11,
                 from /usr/local/include/ITK-5.2/itkSymmetricEigenAnalysis.h:23,
                 from /usr/local/include/ITK-5.2/itkSymmetricSecondRankTensor.h:29,
                 from /usr/local/include/ITK-5.2/itkImageIOBase.h:30,
                 from /usr/local/include/ITK-5.2/itkGDCMImageIO.h:32,
                 from /home/3484681/Área de Trabalho/scr (2)/teste202.cxx:1:
/usr/local/include/ITK-5.2/itkeigen/Eigen/src/Core/DenseBase.h:41:34: note: ‘class Eigen::DenseBase<Derived>’ defined here

   41 | template<typename Derived> class DenseBase

The cmakelists.txt file is like this:

find_package(Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${EIGEN3_INCLUDE_DIR})


add_executable(teste202 teste202.cxx)
target_link_libraries(teste202 ${ITK_LIBRARIES})
target_link_libraries(teste202 fmt::fmt)
target_link_libraries (teste202 Eigen3::Eigen)

I also tryed

-DEigen3_DIR=$HOME/mypackages/share/eigen3/cmake/

and

set(-DEigen3_DIR=$HOME/mypackages/share/eigen3/cmake/)

Thanks in advance,

Rafael S.

When configuring ITK, you should enable ITK_USE_SYSTEM_EIGEN, and provide the path to it. Alternatively, you could use Eigen bundled with ITK. Take a look at this documentation:

Hi @Oddone-Scatena, the Eigen used in ITK is not mangled, so you cannot have a different external version of Eigen in your project. You have three options:

A) Use the internal Eigen used in ITK: for example #include <itkeigen/Eigen/Core> instead of the native #include <Eigen/Core>.

B) Build ITK with the Eigen version you want, or the one installed in your system. For that, you have to build ITK with the CMake flags: -DITK_USE_SYSTEM_EIGEN:BOOL=ON and point to it with -DEigen3_DIR:PATH=/path/eigen3/cmake. And then use that Eigen in your own code with: #include <Eigen/Core>

C) Another option, and this is the reason that ITK do not mangle Eigen is the following:
You can reuse the internal Eigen used in ITK, and still use the native includes, i.e. #include <Eigen/Core>. For that you need the following CMake code:

2 Likes