配置vtk(Win8.1 + VS2012+VTK-5.10.1)

1.下载相关软件

vtk-5.10.1.zip和vtkdata-5.10.1.zip

http://www.vtk.org/files/release/5.10/vtk-5.10.1.zip

http://www.vtk.org/files/release/5.10/vtkdata-5.10.1.zip 

cmake-2.8.12.2.zip:

http://www.cmake.org/cmake/resources/software.html

 

2.解压以上三个包,放在E:vtk下,vtk-5.10.1和vtkdata-5.10.1分别改名为VTKsourcecode和VTKData。

安装与配置VTK

1. 解压 cmake-2.8.2-win32-x86.zip,管理员身份运行{解压目录}incmake-gui.exe,设置sourse code目录为F:VTKVTKsourcecode,build目录为F:VTKVTKbin

 

 按 configure 按钮,选Visual Studio 10编译器,我选的是VS2010(尽量不要用64位的),然后cmake会描所需要的文件。

需要勾选的(按个人需要):

vtk_data_root,浏览到例子数据所在位置,如“d:vtkvtkdata”
build_examples:勾选上则编译例子,
build_testing: 勾选上则编译测试代码,也是例子
vtk_use_parallel:勾选(并行计算相关的,不做就不选)
build_shared_libs: 设置为on,将会多生成 dll 文件,这些dll需要拷到windows/system目录下。要是用静态库编程,即off时,应用程序可以独立运行,尺寸也比较大,要是用动态库编程, 即on时,应用程序必须找到动态库才能运行,但尺寸可以做得比较小。

vtk_use_GUIsupport:勾选
再次Configure后,有一项红色为vtk_use_mfc,再勾选后Configure。
以上正确完成后点击Generate。

注意:

1)、如果找不到某些选项,记得选中 Advanced ,这样所有的都出来了

2)、所有项目会变成灰色后后可以点击 Generate,否则就不停地的修改cmake 选项,然后再按configure 按键,直到没有选项预示为红色

2. 用 vc++2010打开 D:VTKVTKbinUtilitiesMaterialLibrary目录下的 MaterialLibrary.sln 文件,右键点击All_Build选择重新生成。

3. 若 build_shared_libs 选择On,把D:VTKVTKbininDebug里生成的vtksys.dll文件拷到WindowsSysWOW64或C:WindowSystem32目录下。或者打开VS2010的属性管理器(视图->其他窗口->属性管理器),双击任意“Microsoft.Cpp.Win32.user”,弹出属性页,在里面VC++目录的 Library Directories 中将bin文件夹中的Debug包括进去。

4. 打开D:VTKVTKbin目录下的VTK.sln,右键点击All_Build选择重新生成。
    若build_shared_libs选择On,中途涉及MFC的示例会出错,

错误

Link错误:

a.在Solution Explorer中分别找到vtkDLG、vtkMDI、vtkSDI这三个项目,

找到F:VTKVTKsourcecodeExamplesGUIWin32vtkMFC下,发现有三个文件夹

 

分别点击进去,找到CMakeLists.txt文件,修改其中内容如图所示

 

再找到F:VTKVTKsourcecodeExamplesGUIWin32发现文件夹

 

点击进去,找到CMakeLists.txt文件,修改其中内容如图所示

 

错误

This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.

解决办法为:

找到五个工程:vtkDLG、vtkMDI、vtkSDI、Win32SampleMFC、vtkMFC

前三个路径:F:VTKVTKsourcecodeExamplesGUIWin32vtkMFC

Win32SampleMFC路径:F:VTKVTKsourcecodeExamplesGUIWin32

a.打开前四个工程源文件中的stdAfx.h,

如果找不到,则打开<资源文件>中的stdAfx.cpp,打开找到其中#include "stdAfx.h" ,右击:<打开"stdAfx.h">

b.打开vtkMFC工程的vtkMFCWindow.cpp,按如下方法修改

c.一个 vtkMFCWindow.cpp, 在{解压的vtk5.10.1的目录}GUISupportMFC

)我的电脑中路径是F:VTKVTKsourcecodeGUISupportMFC


前三个文件中的stdAfx.h修改如下

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
 #ifndef WINVER        // Allow use of features specific to Windows 95 and Windows NT 4 or later.
 #define WINVER 0x0501// 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 0x0501// 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 0x0501// 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 0x0601// Change this to the appropriate value to target IE 5.0 or later.
 #endif

另外还要改动文件vtkMFCWindow.cpp中的部分代码:

// Allow use of features specific to Windows 95 and Windows NT 4 or later.
#ifndef WINVER
#define WINVER 0x0501
#endif

// Define _WIN32_WINNT and _WIN32_IE to avoid the following error with Visual
// Studio 2008 SP1:
// "C:Program FilesMicrosoft SDKsWindowsv6.0Aincludesdkddkver.h(217) :
// fatal error C1189: #error :  _WIN32_WINNT settings conflicts with _WIN32_IE
// setting"

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501// =_WIN32_WINNT_NT4
#endif
#ifndef _WIN32_IE
#define _WIN32_IE 0x0601//=_WIN32_IE_IE60SP1
#endif

此时,应该没有问题了。

若出现cannot find vtkMFC.lib则是由于cmake阶段未勾选vtk_use_mfc

5、一切修改完成之后,再次右键点击All_Build选择重新生成

然后右击Cone6,Win32SampleMFC,选择调试->启动新实例,这时可以看到正确运行的程序了。(注:Cone6需要你CMAKE时勾选build_examples:)

注意:如果还想把VTK相关的头文件、动态链接库文件等提取出来,以便用于其他项目的开发,可以编辑VTK.sln项目中的‘INSTALL’工程,右击该工程,选择Project Only->Build Only INSTALL选项,VTK里的所有头文件以及相关的库文件等,即会被提取到CMAKE_INSTALL_PREFIX选项所指定的目录里,默认路径是C:/Program Files/VTK(这个在Cmake中的configure配置里出现的有)

原文地址:https://www.cnblogs.com/guozw/p/6607829.html