简体   繁体   English

在64位上迁移32位应用程序时遇到的问题

[英]problems in migrating 32bit application on 64 bit

I am trying to migrate existing c++ 32 code to 64 code on windows7 with visual studio 2010.i never did 64bit compilation before. 我正在尝试使用Visual Studio 2010在Windows7上将现有的c ++ 32代码迁移到64代码。我以前从未进行过64位编译。 with the help of internet references i did the setup for 64 bit compilation. 借助互联网参考,我进行了64位编译的设置。 like VS2010 with 64 bit compiler etc and other configuration changes. 例如VS2010,带有64位编译器等,以及其他配置更改。 In the preprocessor i removed WIN32 and added WIN64. 在预处理器中,我删除了WIN32,并添加了WIN64。 i have some other pre-processors like OS_WIN_32 and some other which are specific in my code. 我还有一些其他的预处理器,例如OS_WIN_32和其他一些在我的代码中特定的预处理器。 In the code wherever WIN32 was getting used i added extra condition as || 在无论使用WIN32的代码中,我都添加了||作为附加条件。 WIN64 this is just to ensure that application should get compiled with win32 as well as win64. WIN64只是为了确保应用程序应同时使用Win32和Win64进行编译。 When i am trying to compile the code i am getting the compilation error saying 当我尝试编译代码时,出现编译错误提示

fatal error C1189: #error : Only one of the WIN32 and WIN64 symbols should be defined 严重错误C1189:#error:仅应定义WIN32和WIN64符号之一

this error is coming from the local code where we have a check whether both WIN32 and WIN64 are defined. 此错误来自于我们检查WIN32和WIN64是否都已定义的本地代码。 that code is as shown below. 该代码如下所示。

#if defined WIN32 && defined WIN64
# error Only one of the WIN32 and WIN64 symbols should be defined
#endif

in VS2010 if macros are not enabled then the code inside the macro gets greyed out. 在VS2010中,如果未启用宏,则宏中的代码将变灰。 in my code also the above error is greyed out. 在我的代码中,上述错误也显示为灰色。 but still i am getting that error. 但我仍然收到该错误。

The code where i added WIN64 is including windows.h. 我在其中添加WIN64的代码包括windows.h。 for reference givine it below. 供参考,请在下面参考。

#if defined WIN32 || defined WIN64
#include <windows.h>
#include <process.h>
#endif

So my question is why i am getting this error? 所以我的问题是为什么我会收到此错误? shouldnt we add windows.h for 64bit compilation.? 我们不应该为64位编译添加Windows.h吗? i tried by commenting this inclusion but i am getting other errors wrt HANDLE which are used in the code. 我尝试通过评论此包含项来尝试,但是我在代码中使用了WRT HANDLE时遇到其他错误。 If i go to WIN32 definition VS2010 is pointing to a definition in windef.h file. 如果我转到WIN32定义,VS2010指向windef.h文件中的定义。 This file is present in Microsoft SDKs\\windows\\v7.0A\\include folder ie not my local code. 该文件位于Microsoft SDKs \\ windows \\ v7.0A \\ include文件夹中,即不是我的本地代码。 for referance that definition is given below. 作为参考,下面给出定义。

#ifndef WIN32
#define WIN32
#endif

So i want to know why compiler is getting both pre-processors WIN32 and WIN64. 所以我想知道为什么编译器会同时获得预处理器WIN32和WIN64。

Thanks in advance for your help. 在此先感谢您的帮助。

You shouldn't define either yourself. 您不应该自己定义。 The macro's that should be used to check this are 用于检查此宏的是

_WIN32 // always defined for Windows apps
_WIN64 // only defined for x64 compilation

These are defined by the compiler (see here ). 这些由编译器定义(请参见此处 )。

Often, the IDE adds the unprefixed macros to the commandline to not let legacy projects which use the non-documented unprefixed versions fail to build. 通常,IDE会将未添加前缀的宏添加到命令行中,以使使用未记录的未添加前缀的旧项目无法生成。 The fact that they work is not a reason to use them, when documented alternatives are present. 当有记录的替代方案存在时,它们起作用的事实并不是使用它们的原因。


It boils down to this: 归结为:

#ifdef _WIN32
  // We're on Windows, yay!
#ifdef _WIN64
  // We're on x64! Yay!
#else // _WIN64
  // We're on x86 (or perhaps IA64, but that one doesn't matter anymore). Yay!
#endif // _WIN64
#else // _WIN32
  // We're not on Windows, maybe WindowsCE or WindowsPhone stuff, otherwise some other platform
 #endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM