CMakeLists.txt文件中的config Eigen [英] config Eigen in CMakeLists.txt file
问题描述
当我在CMakeLists.txt文件中配置特征库时,如下所示:
When I config Eigen library in CMakeLists.txt file as follows:
cmake_minimum_required(VERSION 3.14)
project(helloworld)
add_subdirectory(tests)
add_subdirectory(deps/eigen)
set(SRC_LIST main.cpp)
add_executable(hello ${SRC_LIST})
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries(hello eigen)
我收到了cmake错误
I got the cmake error as
CMake Error at build/deps/eigen/Eigen3Config.cmake:20 (include):
The file
/Users/joe/codecplus/build/deps/eigen/Eigen3Targets.cmake
was generated by the export() command. It may not be used as the argument
to the include() command. Use ALIAS targets instead to refer to targets by
alternative names.
Call Stack (most recent call first):
CMakeLists.txt:9 (find_package)
有人可以帮我吗?不知道这里出了什么问题.非常感谢.
Can anybody help me out? Don't know what is going wrong here. Thanks very much.
推荐答案
您使用两种方式在同一时间包括3d-party项目(Eigen):
You use two ways for including 3d-party project (Eigen) at the same time:
-
add_subdirectory()
find_package()
这是错误的.求助于单一方式:
This is wrong. Resort to a single way:
-
仅具有
add_subdirectory
:
add_subdirectory(deps/eigen)
# ...
target_link_libraries(hello Eigen3::eigen)
仅使用 find_package()
:
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
target_link_libraries(hello Eigen3::eigen)
请注意,这两种方法都使用 Eigen3 :: eigen
目标而不是 eigen
进行链接.仅此名称适用于第二种方法,有关本征用法的文档中对此进行了描述.
Note, that both approaches uses Eigen3::eigen
target instead of eigen
for link with. Only this name works with the second approach, and it is described in the documentation for Eigen usage.
这篇关于CMakeLists.txt文件中的config Eigen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!