每次我尝试编译代码时,都会遇到大量错误。这对我的代码来说不是问题,因为它在另一台计算机上运行得很好。我尝试重新安装和修复,但这没有帮助。这是完整的错误消息:
1>------ Build started: Project: Raptor Triangle 2, Configuration: Debug Win32 ------
1> Raptor Triangle 2.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(57): error C2011: 'vc_attributes::YesNoMaybe' : 'enum' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(57) : see declaration of 'vc_attributes::YesNoMaybe'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(67): error C2011: 'vc_attributes::AccessType' : 'enum' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(67) : see declaration of 'vc_attributes::AccessType'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(81): error C2011: 'vc_attributes::Pre' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(81) : see declaration of 'vc_attributes::Pre'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(78): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(112): error C2011: 'vc_attributes::Post' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(112) : see declaration of 'vc_attributes::Post'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(109): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(143): error C2011: 'vc_attributes::FormatString' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(143) : see declaration of 'vc_attributes::FormatString'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(155): error C2011: 'vc_attributes::InvalidCheck' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(155) : see declaration of 'vc_attributes::InvalidCheck'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(152): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(165): error C2011: 'vc_attributes::Success' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(165) : see declaration of 'vc_attributes::Success'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(176): error C2011: 'vc_attributes::PreBound' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(176) : see declaration of 'vc_attributes::PreBound'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(173): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(186): error C2011: 'vc_attributes::PostBound' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(186) : see declaration of 'vc_attributes::PostBound'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(183): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(196): error C2011: 'vc_attributes::PreRange' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(196) : see declaration of 'vc_attributes::PreRange'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(193): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(208): error C2011: 'vc_attributes::PostRange' : 'struct' type redefinition
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(208) : see declaration of 'vc_attributes::PostRange'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(205): error C3094: 'repeatable': anonymous usage not allowed
1> e:\programs\c++\raptor triangle 2\raptor triangle 2\predefined c++ attributes (compiler internal)(147) : see declaration of 'repeatable'
1> attribute can only be applied to: 'class', 'struct'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245): error C2370: 'SA_Yes' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(245) : see declaration of 'SA_Yes'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246): error C2370: 'SA_No' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(246) : see declaration of 'SA_No'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(247): error C2370: 'SA_Maybe' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(247) : see declaration of 'SA_Maybe'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(250): error C2370: 'SA_NoAccess' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(250) : see declaration of 'SA_NoAccess'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(251): error C2370: 'SA_Read' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(251) : see declaration of 'SA_Read'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(252): error C2370: 'SA_Write' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(252) : see declaration of 'SA_Write'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(253): error C2370: 'SA_ReadWrite' : redefinition; different storage class
1> c:\program files\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(253) : see declaration of 'SA_ReadWrite'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
帮助?哈哈。我不明白。我查找了错误代码,但无法弄清楚要做什么。
此外,如果需要,我可以发布代码,但它很长。
编辑:我解决了,但我不明白为什么。我摆脱了我的行,包括我需要Sleep()的windows.h。我仍然不明白为什么这很重要。答案 0 :(得分:4)
您需要按以下方式形成头文件:
#ifndef HEADERFILENAME_DEF
#define HEADERFILENAME_DEF
/* all declarations here */
#endif
这样可以防止双重包含头文件。
答案 1 :(得分:4)
C2370的另一个原因是当存在包含常量的头文件的多个副本时。
然后,不同的项目访问同一个头文件的不同副本,打破'#pragma once'并导致'C2370重新定义;不同的存储类'。
文件复制存在的一个常见原因是开发人员在存在全局可访问的SDK时制作了从属库头的本地副本。
答案 2 :(得分:2)
目标文件必须已过期。尝试一个干净的构建 - 即清洁/构建。 windows.h
应该与它无关。
答案 3 :(得分:0)
VS2008遇到了同样的问题。我决定:
change Yes (/Wp64) --> No