VTK+VS10(64bitWin7)安装配置

1.下载:**vtk-5.10.1.zip**源程序**vtkdata-5.10.1.zip** 数据(vtk相关安装程序下载:http://vtk.org)**cmake-2.8.2-win32-x86.zip**(cmake程序下载:[http://www.cmake.org/HTML/Index.html](http://www.cmake.org/HTML/Index.html))
 
2.安装cmake,选择添加环境变量
 
3.将 vtk-5.10.1.zip 解压到d:\VTK\VTKsourcecode, 将vtkdata-5.10.1.zip解压到d:\VTK\vtkdata
 
4.管理员身份运行cmake-gui,设置source code目录为d:\VTK\VTKsourcecode,build目录为D:\VTK\VTKbin
 
5.configure,选Visual Studio 10编译器,然后cmake会描所需要的文件(不必理会not found等信息)。
 
6.选择advanced,选择需要添加的功能,继续configure![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2013/09/wpid-ca9e6af7bc3edf906157ec20f56cabe0_39751379.png)
 
7.如果继续有红色的背景,继续configure,整个框白色的时候,generate,done。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2013/09/wpid-ca9e6af7bc3edf906157ec20f56cabe0_39837990.png) 
 
8.用vs打开D:\VTK\VTKbin\Utilities\MaterialLibrary目录下的 MaterialLibrary.sln 文件,右键点击All_Build选择重新生成。
 
9.若 build_shared_libs 选择On,把D:\VTK\VTKbin\bin\Debug里生成的vtksys.dll文件拷到windows/system目录下。或者打开VS2010的属性管理器(视图->其他窗口->属性管理器),双击任意“Microsoft.Cpp.Win32.user”,弹出属性页,在里面VC++目录的 Library Directories 中将bin文件夹中的Debug包括进去。
 
10.打开D:\VTK\VTKbin目录下的VTK.sln,右键点击All_Build选择重新生成。编译会花费大约半个小时。先关闭360,因为编译的时候360可能会误认为生成了木马。
此处可能出现两种error。
`**第一种错误类似下面这样:是vtkDLG、vtkMDI、vtkSDI、Win32SampleMFC这四个项目缺少lib文件引起的**
4 > SampleDoc.obj : error LNK2019 : 无法解析的外部符号 "__declspec(dllimport) public: static class vtkDataSetReader * __cdecl vtkDataSetReader::New(void)" (__imp_ ? New@vtkDataSetReader@@SAPAV1@XZ),该符号在函数 "protected: __thiscall CSampleDoc::CSampleDoc(void)" ( ? ? 0CSampleDoc@@IAE@XZ) 中被引用
`
**解决方法:**
以Win32SampleMFC项目为例,右键项目->链接器->附加依赖项->编辑->加入vtkIO.lib,再将vtkIO.lib文件复制一份到D:\vtk\VTKbin\Examples\GUI\Win32\SampleMFC文件夹下。其他三个类似。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2013/09/wpid-ca9e6af7bc3edf906157ec20f56cabe0_40600102.png)  ****
**第二种错误类似下面这样:是vs版本问题**
`
This file requires _WIN32_WINNT to be #defined at least to 0x0403\. Value 0x0501 or higher is recommended.
`
**解决办法:**
找到五个工程:vtkDLG、vtkMDI、vtkSDI、Win32SampleMFC、vtkMFC
a.对于vtkDLG、vtkMDI、vtkSDI、Win32SampleMFC,打开<资源文件>中的stdAfx.cpp,打开找到其中#include "stdAfx.h" ,右击:<打开"stdAfx.h">,改成红色斜体这样子。
`
#**define**  WINVER **_ 0x0601_**      // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #**endif** #**ifndef**  _WIN32_WINNT     // Allow use of features specific to Windows NT 4 or later. #**define**  _WIN32_WINNT  **_0x0601  _**    // Change this to the appropriate value to target Windows 98 and Windows 2000 or later. #**endif**              #**if**  _MSC_VER  >=   1300 #**ifndef**  _WIN32_WINDOWS     // Allow use of features specific to Windows 98 or later. #**define**  _WIN32_WINDOWS  _**0x0601  **_ // Change this to the appropriate value to target Windows Me or later. #**endif** #**endif** #**ifndef**  _WIN32_IE       // Allow use of features specific to IE 4.0 or later. #**define**  _WIN32_IE _** 0x0800**_    // Change this to the appropriate value to target IE 5.0 or later. #**endif** #**define**  _ATL_CSTRING_EXPLICIT_CONSTRUCTORS   // some CString constructors will be explicit
`
b.对于vtkMFC,打开vtkMFCWindow.cpp,改成红色斜体这样子。
`
**ifndef**  WINVER #**define**  WINVER **_ 0x0601 _**#**endif** // Define _WIN32_WINNT and _WIN32_IE to avoid the following error with Visual // Studio 2008 SP1: // "C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\sdkddkver.h(217) : // fatal error C1189: #error :  _WIN32_WINNT settings conflicts with _WIN32_IE // setting" #**ifndef**  _WIN32_WINNT #**define**  _WIN32_WINNT  **_0x0601 _**  // =_WIN32_WINNT_NT4 #**endif** #**ifndef**  _WIN32_IE #**define**  _WIN32_IE  _**0x0800**_   //=_WIN32_IE_IE60SP1 #**endif**
`
 
11.设置启动项目为Cone6,启动调试,出现下图。期间可能提示dllqtcored4.dll和qtguid4.dll缺失。直接复制一份到D:\vtk\VTKbin\Examples\Tutorial\Step6\Cxx目录即可。
![](http://codeplanet-wordpress.stor.sinaapp.com/uploads/2013/09/wpid-ca9e6af7bc3edf906157ec20f56cabe0_38858351.png) 
 
**参考来源:http://blog.csdn.net/cgcoder/article/details/8262232**
[来自为知笔记(Wiz)](http://www.wiz.cn/i/c09d0bb5 "来自为知笔记(Wiz)")
坚持原创技术分享,您的支持将鼓励我继续创作!