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

来源:互联网 发布:telnet的88端口 编辑:程序博客网 时间:2024/06/05 14:00

.#define _WIN32_WINNT 0x0A00 // =_WIN32_WINNT_NT4


2 附加依赖项,位于项目属性->链接器->输入 ->点击右面的<编辑>,拷入入下述内容(具体可通过查看实例的附加包含目录,切勿直接负责..\..\性质的内容,若想直接复制,请确保新建项目与拟拷配置的项目位于同一文件夹下):

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
..\..\VTK\bin\bin\Debug\vtkRendering.lib
..\..\VTK\bin\bin\Debug\vtkGraphics.lib
..\..\VTK\bin\bin\Debug\vtkImaging.lib
..\..\VTK\bin\bin\Debug\vtkFiltering.lib
..\..\VTK\bin\bin\Debug\vtkCommon.lib
..\..\VTK\bin\bin\Debug\vtksys.lib

ws2_32.lib


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,管理员身份运行{解压目录}\bin\cmake-gui.exe,设置sourse code目录为F:\VTK\VTKsourcecode,build目录为F:\VTK\VTKbin

 

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

 

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

vtk_data_root,浏览到例子数据所在位置,如“d:\vtk\vtkdata”
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:\VTK\VTKbin\Utilities\MaterialLibrary目录下的 MaterialLibrary.sln 文件,右键点击All_Build选择重新生成。

 

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

 

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

错误①

Link错误:

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

找到F:\VTK\VTKsourcecode\Examples\GUI\Win32\vtkMFC下,发现有三个文件夹

 

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

 

再找到F:\VTK\VTKsourcecode\Examples\GUI\Win32发现文件夹

 

点击进去,找到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:\VTK\VTKsourcecode\Examples\GUI\Win32\vtkMFC

Win32SampleMFC路径:F:\VTK\VTKsourcecode\Examples\GUI\Win32

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

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

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

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

)我的电脑中路径是F:\VTK\VTKsourcecode\GUISupport\MFC


前三个文件中的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 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 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配置里出现的有)


原创粉丝点击