gpt4 book ai didi

c++ - ITK安装及示例程序

转载 作者:太空狗 更新时间:2023-10-29 21:24:34 26 4
gpt4 key购买 nike

我是 ITK 的新手,我执行了以下步骤来安装 ITK 并使用它在 VS2010 中编程

  1. 下载 ITK 4.3.1 并使用 CMAKE 构建
  2. 构建成功,我有一个包含库的 lib->Debug 文件夹。
  3. 将 bin 文件夹路径添加到环境可用路径。

以下是我的简单代码...

#include <iostream>
#include <Core/Common/include/itkImage.h>

using namespace itk;
using namespace std;

int main()
{
return 0;
}

以上代码返回

Cannot open include file: 'itkConfigure.h'

我试着搜索那个标题,但没有成功。但是在 C:\InsightToolkit-4.3.1\Modules\Core\Common\src 中我找到了 itkConfigure.h.in 文件。我真的不知道如何处理这个 .in 文件。欢迎任何帮助..

最佳答案

设置项目的最简单方法是再次使用 CMake。尝试创建一个仅包含 CMakeLists.txt 和 main.cpp 的项目。 CMakeLists.txt 应该是这样的:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(ItkTest)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

add_executable(MyTest main.cpp)
target_link_libraries(MyTest ITKCommon)

假设您在名为 ItkProject 的目录中创建了这 2 个文件,然后从 Visual Studio 命令提示符 中执行:

cd <path to ItkProject>
mkdir build
cd build
cmake .. -DITK_DIR="<path to build dir of ITK>"

<path to build dir of ITK>是您运行 CMake 以配置 ITK 项目的地方。它将包含 ITK.sln 文件,但重要的是它还应该包含一个名为 ITKConfig.cmake 的文件。在 cmake 命令中搜索的就是这个文件 find_package(ITK REQUIRED) - 如果 CMake 找不到它,配置将失败。

找到后,它会设置一堆 CMake 变量,然后您可以在自己的 CMakeLists.txt 中使用这些变量,包括 ITK_USE_FILE .

然后调用 include(${ITK_USE_FILE}) 时,这将继续设置您的包含路径、库搜索路径和编译器标志等内容。路径 <path to ItkProject>/Core/Common/include将被添加到 includes 目录中,因此在您的 main.cpp 中,您只需要做:

<strike>#include <Core/Common/include/itkImage.h></strike>
#include "itkImage.h"

无论如何,运行CMake后的最终结果应该是解决方案文件<path to ItkProject>\build\ItkTest.sln已准备好使用 ITK。

关于c++ - ITK安装及示例程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15791122/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com