问题描述
我在CMake项目中使用仅标头库(Eigen)时遇到困难。当我摘下所有与Eigen库相关的部分时,它将进行编译,但不确定如何使用(Eigen)进行构建。请注意,Eigen在Eigen文件夹中有一个CmakeLists.txt,并且它的/ src文件夹中有(* .h和* .cpp)与Matrix操作等有关。
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
- / Build
- / Source
源文件夹中有一堆我的文件(* .h和* .cpp)和/ Eigen(文件夹)。
The Source folder has bunch of my files (*.h and *.cpp) and the /Eigen (folder).
我所做的是:
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
LIST(APPEND CMAKE_CXX_FLAGS
"-std=c++0x
-pthread
${CMAKE_CXX_FLAGS}
-g
-Wall -Wextra ")
ADD_LIBRARY(Eigen ${CMAKE_SOURCE_DIR}/Eigen)
TARGET_INCLUDE_DIRECTORIES(Eigen INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/Eigen>
)
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHERS})
INCLUDE_DIRECTORIES(include)
ADD_LIBRARY(RTT
Def.cpp
Def.h
krnel.cpp
krnel.h
Mesh.cpp
Mesh.h
Mcom.cpp
Mcom.h
timer.h
Identifier.h)
ADD_EXECUTABLE(Rdrtst main.cpp)
TARGET_LINK_LIBRARIES(Rdrtst RTT ${GTK3_LIBRARIES} Eigen)
当我cd到/ Build并键入(Cmake ../Source)
When i cd to /Build and type (Cmake ../Source )
我得到以下信息:
[/../Build]$ cmake ../Source
-- Configuring done
CMake Error: Cannot determine link language for target "Eigen".
CMake Error: CMake can not determine linker language for target:Eigen
-- Generating done
-- Build files have been written to: /../../MyProject/Build
本征文件夹包含CMakeLists.txt,其内容如下:
The eigen folder has the CMakeLists.txt with the following content :
include(RegexUtils)
test_escape_string_as_regex()
file(GLOB Eigen_directory_files "*")
escape_string_as_regex(ESCAPED_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
foreach(f ${Eigen_directory_files})
if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/[.].+" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/src")
list(APPEND Eigen_directory_files_to_install ${f})
endif()
endforeach(f ${Eigen_directory_files})
install(FILES
${Eigen_directory_files_to_install}
DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel
)
add_subdirectory(src)
推荐答案
您只需要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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!