关于Visual Studio:C ++编译器错误C2371-WCHAR的重新定义

关于Visual Studio:C ++编译器错误C2371-WCHAR的重新定义

C++ Compiler Error C2371 - Redefinition of WCHAR

当我包含本身包含odbcss.h的头文件时,出现C ++编译器错误C2371。 我的项目设置为MBCS。

C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\include\\odbcss.h(430) :
error C2371: 'WCHAR' : redefinition; different basic types 1>
C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\include\\winnt.h(289) :
see declaration of 'WCHAR'

我在odbcss.h中看不到任何可以避免这种情况的定义。 其他人看到了吗?


这是一个已知的错误-请访问Microsoft Connect网站:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98699

如果将应用程序编译为Unicode而不是MBCS,则不会发生该错误。


在网络上的各个论坛上有六篇关于此的文章-当在MFC中使用odbcss.h时,这似乎是一个问题。大多数答案涉及更改包含标头的顺序(巫毒调试)。包含odbcss.h的标头在其本机项目中可以很好地编译,但是当它包含在其他项目中时,则会出现此错误。我们甚至把它放在了后者的stdafx.h中,紧接在MFC的基本库之后,仍然没有乐趣。最后,我们通过将其移动到原始项目中的cpp文件中来解决该问题,该项目不使用MFC(无论如何应该完成此操作-但这不是我们的代码)。因此,我们有一种解决方法,但没有真正的解决方案。


这有帮助吗?

http://bytes.com/forum/thread602063.html

来自线程的内容:

Bruno van Dooren [MVP VC++] but i know the solution of this problem.
it solves by changing project setting of"Treat wchar_t as Built-in
Type" value"No (/Zc:wchar_t-)". But I am using"Xtreme Toolkit
Professional Edition" for making good look & Feel of an application,
when i fix the above problem by changing project settings a new
linking errors come from Xtreme Toolkit Library. So what i do to fix
this problem, in project setting"Treat wchar_t as Built-in Type"
value"yes" and i wrote following statements where i included wab.h
header file. You can change that setting on a per-codefile basis so
that only specific files are compiled with that particular setting. If
you can solve your problems that way it would be the cleanest
solution.

#define WIN16

#include"wab.h"

#undef WIN16

and after that my project is working fine and all the things related to WAB is also working fine. any one guide me, is that the right way
to solve this problem??? and, will this have any effect on the rest of
project?? I wouldn't worry about it. whatever the definition, it is a
16 bit variable in both cases. I agree that it isn't the best looking
solution, but it should work IF WIN16 has no other impact inside the
wab.h file.

--

Kind regards, Bruno van Dooren bruno_nos_pam_van_dooren@hotmail.com
Remove only"_nos_pam"


当您重新声明与已经声明的变量同名的变量时,会发生此错误。您是否看过odbcss.h是否已声明您已经拥有的变量?


推荐阅读