I have simple C++ project that is organized like this:
project
|-- Input
| |-- data.cpp <-- this file used eigen3
| |--- CmakeLists.txt
|--- main.cpp
|--- CmakeLists.txt
Basically I am trying to create .so library from input and have main.cpp calls functions in it. CMake under project looks like this
cmake_minimum_required(VERSION 3.20)
project(myProj)
find_package (Eigen3 REQUIRED)
# Dependencies paths
set(EIGEN_INC_DIR ${EIGEN3_INCLUDE_DIR})
if (TARGET Eigen3::Eigen)
message("Eigen was found"). <--- I do see this message so Eigen3 package is found
endif (TARGET Eigen3::Eigen)
add_subdirectory(Input)
<more cmake commands to link with main.cpp>
CMake under Input looks like this
cmake_minimum_required(VERSION 3.20)
set(TARGET_LIB_INPUT input_data)
set(SRC_FILES
Data.cpp
)
set(INC_DIRS
${EIGEN_INC_DIR}
)
include_directories(${INC_DIRS})
add_library (${TARGET_LIB_INPUT} SHARED ${SRC_FILES})
target_link_libraries (${TARGET_LIB_INPUT} Eigen3::Eigen)
in file data.cpp, I do the following include to eigen3
#include <eigen3/Eigen/Core>
But I keep getting the error fatal error: 'eigen3/Eigen/Core' file not found I see the build command clearly include eigen directory: -I /usr/local/include/eigen3
Anybody knows what am I missing here? Thanks for help
The include directory defined in Eigen3::Eigen
already includes eigen3
(eg, /usr/include/eigen3
on Ubuntu). So you should use #include <Eigen/Core>
.
You can check this by:
find_package(Eigen3 REQUIRED CONFIG)
# checking property of the target
get_target_property(inc_dir Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
message("[DEBUG] inc_dir: ${inc_dir}")
# or checking the Eigen variable
message("[DEBUG] EIGEN3_INCLUDE_DIRS: ${EIGEN3_INCLUDE_DIRS}")
EIGEN3_INCLUDE_DIRS
is defined in here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.