Not found Eigen3_DIR when configuring a cmake project in Windows

  • 9 months ago
Comment

ChatGPT
1 / 1

The "Eigen3_DIR" error typically occurs when CMake cannot locate the Eigen3 package during configuration. Eigen is a C++ template library for linear algebra, and CMake uses the Eigen3_DIR variable to find the Eigen3 package configuration files.

To resolve this issue and successfully configure your CMake project, follow these steps:

  1. Download Eigen Library:
    Download the Eigen3 library from the official website: https://eigen.tuxfamily.org/dox/GettingStarted.html
    Extract the downloaded archive to a location on your system.

  2. Provide the Eigen3 Directory to CMake:
    When running CMake to configure your project, you need to provide the path to the directory where Eigen3 is located. This can be done using the -DEigen3_DIR option.

    For example, if you're using the command line, navigate to your project's build directory and run:

    sh
    cmake -DEigen3_DIR=<path_to_eigen3_dir> <path_to_source_code>

    Replace <path_to_eigen3_dir> with the actual path to the directory containing the extracted Eigen3 library, and <path_to_source_code> with the path to your project's source code.

  3. CMakeLists.txt Modifications:
    Make sure that your project's CMakeLists.txt file includes the necessary lines to find the Eigen3 package. Add the following lines to your CMakeLists.txt:

    cmake
    find_package(Eigen3 REQUIRED)
    include_directories(${EIGEN3_INCLUDE_DIR})

    Place these lines near the top of your CMakeLists.txt file, before any targets are defined.

  4. Configure and Generate:
    After adding the required lines to your CMakeLists.txt file, run the CMake configuration again:

    sh
    cmake -DEigen3_DIR=<path_to_eigen3_dir> <path_to_source_code>

    This time, CMake should be able to locate the Eigen3 package and properly configure your project.

  5. Generate and Build:
    After successful configuration, generate the build files and build your project using the appropriate build tool (e.g., make, Visual Studio, etc.).

By following these steps, you should be able to resolve the "Eigen3_DIR not found" error and successfully configure your CMake project with the Eigen3 library on Windows.