在我的 Cmake 项目中使用 Eigen Lib?
问题描述
我在我的 CMake 项目中使用仅标头库 (Eigen) 时遇到困难.当我删除与 Eigen 库相关的所有部分时,它会编译,但不确定如何使用 (Eigen) 进行构建.请注意,Eigen 在 Eigen 文件夹中有一个 CmakeLists.txt,它有/src 文件夹,其中包含与矩阵运算等相关的(*.h 和 *.cpp)...
I am having difficulty using a header-only library (Eigen) in my CMake project. When i take off all the portion related to Eigen library it compiles, but not sure how to build with (Eigen). Note that Eigen has a CmakeLists.txt in Eigen folder, and it has /src folder having (*.h and *.cpp) related to Matrix operation etc...
我的程序结构如下
Myproject(文件夹)由:
Myproject (folder) is composed of :
- CmakeLists.txt
- /构建
- /来源
Source 文件夹中有一堆我的文件(*.h 和 *.cpp)和/Eigen(文件夹).
The Source folder has bunch of my files (*.h and *.cpp) and the /Eigen (folder).
我所做的是:
当我 cd 到/Build 并输入 (Cmake ../Source )
When i cd to /Build and type (Cmake ../Source )
我得到以下内容:
eigen 文件夹中有 CMakeLists.txt ,内容如下:
The eigen folder has the CMakeLists.txt with the following content :
推荐答案
您只需要 INCLUDE_DIRECTORIES 中的正确路径(还要确保包含正确的文件夹或子文件夹,具体取决于您在 C++ 文件中是否使用 #include Eigen/something.h 或 #include something.h )因此,删除行 ADD_LIBRARY(Eigen ... 和 TARGET_LINK_LIBRARIES Eigen.
You just need the correct path in INCLUDE_DIRECTORIES (also make sure to include the correct folder or subfolder, depending if in your c++ file you are using #include Eigen/something.h or #include something.h ) So, remove the lines ADD_LIBRARY(Eigen ... and TARGET_LINK_LIBRARIES Eigen.
为了排除故障,您还可以包含 Eigen 文件夹的绝对路径,然后当您运行时,将其转换为相对路径
For troubleshooting, you can also include the absolute path of the Eigen folder , and then when you get it working, transform it in a relative path
这篇关于在我的 Cmake 项目中使用 Eigen Lib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!