几个VTK编译错误的解决 (VTK5.8 + VS2010)
2011-12-14 17:14 John's blog 阅读(2200) 评论(0) 编辑 收藏 举报在对VTK项目进行编译的过程中,可能会出现几个共性的错误,将其的解决方法列举如下:
错误一:
fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403
原因:
版本迁移设置的系统最低版本过低
Visual C++ 2010 no longer supports targeting Windows 95, Windows 98, Windows ME, or Windows NT. If your WINVER or _WIN32_WINNT macros are assigned to one of these versions of Windows, you must modify the macros. When you upgrade a project that was created by using an earlier version of Visual C++, you may see compilation errors related to the WINVER or _WIN32_WINNT macros if they are assigned to a version of Windows that is no longer supported(From MSDN)
直接原因-在atlcore.h中有如下三行代码:
#if _WIN32_WINNT < 0x0403
#error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
#endif
解决方法:
在VTK目录中所有的stdafx.h文件中参照 http://msdn.microsoft.com/en-us/library/aa383745.aspx 修改WINVER,_WIN32_WINNT,_WIN32_WINDOWS和_WIN32_IE的定义,例如:#define WINVER 0x0501
错误二:
error C2371: 'char16_t' : redefinition
原因:
在VTK项目文件生成的过程中选择了Matlab支持(MEX),并且采用了VS2010及以上的编程环境(http://connect.microsoft.com/VisualStudio/feedback/details/498952/vs2010-iostream-is-incompatible-with-matlab-matrix-h):
I looked at the source code for matrix.h <core/matlab/include/matrix.h>
It has a definition for char16_t
"typedef CHAR16_T char16_t;". Also the C++ header "Microsoft Visual Studio 10.0\VC\include\yvals.h" also defines the same identifier(char16_t). Because of these two definition we get the redefinition error when matrix.h and iostream.h(it internally includes yvals.h) are included in some cpp file.
Declaration of char16_t in the yvals.h is newly introduced in dev10 and was not there in VS2008. Therefore you are getting this redefinition error now on VS 2010(Dev10).
解决方法一(未经后续测试):
//added by John for solving conflict with VS2010
#if (_MSC_VER) < 1600 //VS2010
# ifndef __STDC_UTF_16__
# ifndef CHAR16_T
# if defined(_WIN32) && defined(_MSC_VER)
# define CHAR16_T wchar_t
# else
# define CHAR16_T UINT16_T
# endif
typedef CHAR16_T char16_t;
# endif
#endif
#else
#include <yvals.h>
#endif//VS2010
解决方法二(未经后续测试):
将Matrix.h中的所有char16_t更名
错误三:
LNK4199: /DELAYLOAD:vtkIO.dll ignored; no imports found from vtkIO.dll
原因:
DelayLoad (摘选自《深入分析DelayLoad》 http://blog.csdn.net/panda1987/article/details/5936770 )
我们知道,dll的的载入有两种最基本的方法:隐式加载和显式加载。所谓隐式加载就是上一篇文章中介绍的方法,通过PE的输入表在进入入口函数之前将dll加载到内存空间。显式加载就是用LoadLibrary和GetProAddress的方法在需要的时候将dll加载到进程空间。这两种方法都是我们最常用的。那什么叫delay load呢?
被指定为delay load的dll只有当需要的时候才会真正载入进程空间,也就是说如果没有位于该dll中的函数被调用该dll将不被加载。而这个加载过程正是由LoadLibrary和GetProcAddress完成的,当然这一切对程序员是透明的。
这样做的好处是什么?毫无疑问,程序的启动速度快了,因为很多dll在启动的时候可能还没有使用到。甚至有些dll可能在整个生命周期中都未曾使用到,这样用delay load的话这个dll就不需占用任何内存。
解决方法:
由于对于动态库,其加载信息仍然记录在相应的lib文件中,因此,在项目的属性中Linker->Input->Additional Depandencies 中加入vtkIO.lib,或者直接在Cpp的开头加上#pragma comment(lib, " vtkIO.lib")。如果编译提示找不到这个文件,那么还需要在Linder->General->Additional Library Directory 中增加该文件的位置。
如果有人对Lib和Dll的区别不甚清楚,可以参看:http://www.cppblog.com/amazon/archive/2011/01/01/95318.html