# Using ITK + Eigen

**URL:** https://discourse.itk.org/t/using-itk-eigen/5627
**Category:** Engineering
**Created:** [January 13, 2023, 8:18pm UTC](https://discourse.itk.org/t/using-itk-eigen/5627 "2023-01-13T20:18:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Oddone-Scatena](https://discourse.itk.org/user_avatar/discourse.itk.org/oddone-scatena/32/2651_2.png) [@Oddone-Scatena](https://discourse.itk.org/u/Oddone-Scatena)
#### Post date: [January 13, 2023, 8:18pm UTC](https://discourse.itk.org/t/using-itk-eigen/5627/1 "2023-01-13T20:18:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [January 13, 2023, 9:10pm UTC](https://discourse.itk.org/t/using-itk-eigen/5627/2 "2023-01-13T21:10:42Z")

</div>

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:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/v5.3.0/Modules/ThirdParty/Eigen3/CMakeLists.txt#L16-L51>

---

<div class="post-metadata">

### Author: ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)
#### Post date: [January 13, 2023, 9:42pm UTC](https://discourse.itk.org/t/using-itk-eigen/5627/3 "2023-01-13T21:42:37Z")

</div>

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:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/ThirdParty/Eigen3/CMakeLists.txt#L37-L51>
