2013-04-03 89 views
3

我是新來ITK和我做了如下的步驟來安裝ITK,並用它在VS2010ITK安裝示例程序

  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文件非常無知​​。任何幫助是最受歡迎的..

+2

當編譯itk時,你不忘記'nmake install'嗎?如果你把它保存在build目錄中,那是一種你會得到的錯誤。 – Archie

回答

3

設置您的項目最簡單的方法是再次使用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 DIR生成這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將被添加到包括迪爾斯,所以在你的main.cpp中,你只需要做:


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

反正運行CMake的應該是解決方案文件<path to ItkProject>\build\ItkTest.sln這是建立準備後的最終結果使用ITK。

0

我檢查了\ ItkConfig.cmake和那裏定義的路徑應該匹配物理路徑,如果ITK構建未被改動(目錄沒有被重命名),情況就是如此。

# The ITK source tree. 
# For backward compatibility issues we still need to define this variable, although 
# it is highly probable that it will cause more harm than being useful. 
# Use ITK_INCLUDE_DIRS instead, since ITK_SOURCE_DIR may point to non-existent directory 
IF(NOT ITK_LEGACY_REMOVE) 
    SET(ITK_SOURCE_DIR "C:/ITK320") 
ENDIF(NOT ITK_LEGACY_REMOVE) 

# The ITK include file directories. 
SET(ITK_INCLUDE_DIRS "C:/ITK320-build;C:/ITK320/Code/Algorithms;C:/ITK320/Code/BasicFilters;C:/ITK320/Code/Common;C:/ITK320/Code/Numerics;C:/ITK320/Code/IO;C:/ITK320/Code/Numerics/FEM;C:/ITK320/Code/Numerics/NeuralNetworks;C:/ITK320/Code/SpatialObject;C:/ITK320/Utilities/MetaIO;C:/ITK320/Utilities/NrrdIO;C:/ITK320-build/Utilities/NrrdIO;C:/ITK320/Utilities/DICOMParser;C:/ITK320-build/Utilities/DICOMParser;C:/ITK320-build/Utilities/expat;C:/ITK320/Utilities/expat;C:/ITK320/Utilities/nifti/niftilib;C:/ITK320/Utilities/nifti/znzlib;C:/ITK320/Utilities/itkExtHdrs;C:/ITK320-build/Utilities;C:/ITK320/Utilities;C:/ITK320/Code/Numerics/Statistics;C:/ITK320/Utilities/vxl/v3p/netlib;C:/ITK320/Utilities/vxl/vcl;C:/ITK320/Utilities/vxl/core;C:/ITK320-build/Utilities/vxl/v3p/netlib;C:/ITK320-build/Utilities/vxl/vcl;C:/ITK320-build/Utilities/vxl/core;C:/ITK320-build/Utilities/gdcm;C:/ITK320/Utilities/gdcm/src") 

# The ITK library directories. 
SET(ITK_LIBRARY_DIRS "C:/ITK320-build/bin") 
相關問題