【发布时间】:2019-06-23 10:42:16
【问题描述】:
我一直在尝试在新 PC 上设置 ITK,但当我在项目上运行 CMake 时遇到了问题。
我下载了 ITK 4.8.2,解压它,用 CMake 配置并像往常一样生成。但是,这一次 CMake 发出以下错误:
CMake Error at CMakeLists.txt:4 (find_package):
By not providing "FindITK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ITK", but
CMake did not find one.
Could not find a package configuration file provided by "ITK" with any of
the following names:
ITKConfig.cmake
itk-config.cmake
Add the installation prefix of "ITK" to CMAKE_PREFIX_PATH or set "ITK_DIR"
to a directory containing one of the above files. If "ITK" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
CMakeLists.txt 文件非常棒,只是试图确保正确设置 cmake/ITK:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(ITKTest)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(ITKTest main.cpp)
target_link_libraries(ITKTest ${ITK_LIBRARIES})
我添加了CMAKE_PREFIX_PATH 和ITK_DIR 作为附加条目,后者指向ITK 文件夹的位置。但问题依然存在。
至于它说找不到的文件,一个存在于我设置 cmake 以构建二进制文件的文件夹中。就我而言,两个目录中有两个文件:
--E:\ITK\InsightToolkit-4.8.2-build\ITKConfig.cmake
--E:\ITK\InsightToolkit-4.8.2-build\CMakeFiles\ITKConfig.cmake
【问题讨论】:
-
您确定 FindITK.cmake 存在于您的模块目录中吗?我没有 Windows 机器 ATM,但在 Ubuntu 上的模块位于 /cmake-root/Modules 下。
-
find_package() 的搜索算法在documentation 中有完整描述。尝试在
CMakeFiles下将ITK_DIR设置为E:\\ITK\\InsightToolkit-4.8.2-build(\` should be interpreted by CMake as single backslash). Two things looks suspicious for me: 1. runningcmake CMakeLists.txt. Normally, argument for cmake is source directory, not a script file itself. And it is better to perform out-of-source builds. 2. Having secondITKConfig.cmake`。看起来同一目录已被用作build 和为 ITK 安装一个。 -
@siavashk 刚刚查了一下,不,FindITK.cmake 不在 Modules 目录中。
-
@Tsyvarev 在上面的示例中,我正在运行 CMakeLists.txt 来创建一个 HelloWorld 项目,以验证 ITK 是否配置正确。我将 ITK_DIR 设置为您建议的路径,但是在尝试创建该测试项目时仍然遇到相同的错误。至于目录,源和构建位于单独的子文件夹中(即 E:\ITK\InsightToolkit-4.8.2\ 和 E:\ITK|InsightToolkit-4.8.2-build\ )。
-
` 至于目录,源和构建位于不同的子文件夹中` - 您也需要单独的 build 和 install 子文件夹。