VS2010编译错误:fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x
編譯VTK,MFC時,mfc對版本的要求問題:
解決方法原文鏈接:http://www.cnblogs.com/madhenry/archive/2011/06/29/2093678.html
 
最近拿到一個別人的工程,是使用VS.net創建的,而我的機器上只有vs2010,于是用自帶的轉換工具將它轉換成vs2010的工程,轉換之前我就很擔心,怕轉換完后會出問題,但是沒有辦法,我實在是不想再安一個vs.net了。
? 轉完后果不其然真出了問題,在重新build工程時,報了一大堆錯誤,其中第一個就是“fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended”,然后看錯誤的來源,竟然是atlcore.h,這我就無語了,這是mfc自帶的文件,出錯的可能性基本上為0,于是只好去請教谷大叔,發現很多人都遇到了這個問題,看了幾篇博客和帖子后,大概明白了,應該是_WIN32_WINNT這個宏對應定義的系統的版本號,如果太低的話,編譯器就會認為代碼無法在當前的系統上編譯。
? 說了原因,下面是修改方法,就是在stdafx.h文件中修改相關的定義,修改完后的效果應該如下
(代碼可參見原文)
| #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 | 
| ? | 
| #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 | 
| ? | 
| #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 | 
這樣就應該沒有問題了
參考資料:
(1)http://topic.csdn.net/u/20100801/22/2a271d13-b3e9-419b-906c-039c8f3a5e0e.html
(2)http://blog.csdn.net/dongliqiang2006/archive/2010/08/13/5810055.aspx
(3)http://topic.csdn.net/u/20100401/14/c5b852d1-9934-4056-89f5-4a6041fe73de.html
 
 
 后記:編譯解決這個錯誤后,VTK完全編譯成功!mark一下!
 
總結
以上是生活随笔為你收集整理的VS2010编译错误:fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 青梅竹马的意思
 - 下一篇: 关于编译PCL1.71