I am trying to use Eigen in my project were I use by default CMake Build System. This is my CMakeLists.txt
:
cmake_minimum_required(VERSION 3.14)
project(math VERSION 0.0 DESCRIPTION "" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
option(STATICALLY_LINK "Build for release purposes (statically link everything)" OFF)
if(STATICALLY_LINK)
set(BUILD_SHARED_LIBS OFF)
else()
set(BUILD_SHARED_LIBS ON)
endif()
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} \
-std=c++17 \
-D_GLIBCXX_USE_CXX11_ABI=0 \
-Wall \
-Wformat \
-Wextra \
-Wmissing-include-dirs \
-fdiagnostics-color=always \
-mavx"
)
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()
set(EIGEN3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third-party/eigen)
set(EIGEN3_INCLUDE_DIR ${EIGEN3_DIR}/Eigen)
list(APPEND CMAKE_MODULE_PATH "${EIGEN3_DIR}/cmake")
include_directories(./)
include_directories(${EIGEN3_INCLUDE_DIR})
find_package(Eigen3 3.4.0 NO_MODULE)
set(SOURCES main.cpp)
add_executable(math ${SOURCES})
target_link_libraries(math ${Eigen_LIBRARIES})
Output:
cmake -G "MinGW Makefiles"
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- Could NOT find Eigen3 (missing: Eigen3_DIR)
-- Configuring done (0.2s)
-- Generating done (0.1s)
-- Build files have been written to: C:/Users/Alix/Desktop/math
I found this suggestion: Unable to find Eigen3 with CMake
However, the link claims that,
Go to the Eigen source directory and run the CMake and installation steps
The version I pulled and added as a submodule is: 3.4.0, from the following source: https://gitlab.com/libeigen/eigen/-/tree/master/cmake?ref_type=heads
Commit: 4d54c43
Project in VS Code:
I resolved this issue on my own eventually. It wasn't a major problem. The issue is that Eigen is a single header which is statically link and thus not producing an DLL as I thought initially. Thanks for the effort by other SO members.