VS2010 Beta 1 上基本 C++ 应用程序的多个编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1356653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:40:35  来源:igfitidea点击:

multiple compiling errors with basic C++ application on VS2010 Beta 1

c++visual-studio-2010compilation

提问by user112771

I just recently installed VS2010 Beta 1 from the Microsoft website , I started a basic C++ Win32 Console Application , that generated the following code:

我最近从 Microsoft 网站安装了 VS2010 Beta 1,我启动了一个基本的 C++ Win32 控制台应用程序,它生成了以下代码:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{

return 0;
}

I tried compiling the code just to see how it runs and just then I encountered several(over a 100) compiling errors.

我试着编译代码只是为了看看它是如何运行的,然后我遇到了几个(超过 100 个)编译错误。

Here is the first part of the build output:

这是构建输出的第一部分:

1>ClCompile:
1>  stdafx.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2065: '_In_opt_z_' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): warning C4229: anachronism used : modifiers on data are ignored
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2182: '_invalid_parameter' : illegal use of type 'void'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2491: '_invalid_parameter' : definition of dllimport data not allowed
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(520): error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(527): error C2065: '_In_opt_z_' : undeclared identifier
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(527): error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 10.0\vc\include\crtdefs.h(527): warning C4229: anachronism used : modifiers on data are ignored

pastebinfor the full list

完整列表的pastebin

I thought maybe the include files got mixed up by some other compiler version I have installed previously( I have VS 2008 as well) so I reinstalled VS2010 just to overwrite the headers but that didn't do much.

我想可能包含文件被我之前安装的其他编译器版本混淆了(我也有 VS 2008)所以我重新安装了 VS2010 只是为了覆盖头文件,但这并没有做太多。

Thanks in advance for any help you might offer as I am helpless

预先感谢您提供的任何帮助,因为我很无助

回答by

The problem is here: C:\WinDDK\6001.18001\inc\api\sal.h

问题出在这里:C:\WinDDK\6001.18001\inc\api\sal.h

sal.h defines annotations, which are being used in the CRT headers... The DDK includes its own sal.h, which is obsolete and dones not contain all the annotations.

sal.h 定义了在 CRT 标头中使用的批注... DDK 包括它自己的 sal.h,它已过时并且 dones 不包含所有批注。

There are 2 possible solutions: - change the include paths so that the "C:\Program Files\Microsoft Visual Studio 10.0\VC\include" comes before "C:\WinDDK\6001.18001\inc\api"

有两种可能的解决方案: - 更改包含路径,使“C:\Program Files\Microsoft Visual Studio 10.0\VC\include”位于“C:\WinDDK\6001.18001\inc\api”之前

  • just delete "C:\WinDDK\6001.18001\inc\api\sal.h" :)
  • 只需删除 "C:\WinDDK\6001.18001\inc\api\sal.h" :)

回答by Juriy Petrochenkov

Just use '$(IncludePath);C:\WinDDK\6001.18001\inc\api' as include directories.

只需使用 '$(IncludePath);C:\WinDDK\6001.18001\inc\api' 作为包含目录。

回答by Michael Burr

Something is wrong with your include path. Use the the "/showIncludes" option ("Configuration Properties/C/C++/Advanced/Show Includes" in the IDE's project options) to see what headers are being included from where.

您的包含路径有问题。使用“/showIncludes”选项(IDE 项目选项中的“Configuration Properties/C/C++/Advanced/Show Includes”)查看从何处包含哪些标头。

See this question for more details:

有关更多详细信息,请参阅此问题:

回答by Zoran

I had the same problem after adding the path to the DDK directory in the project property pages under

在项目属性页下添加DDK目录的路径后我遇到了同样的问题

Configuration Properties -> C/C++ -> Additional Include Directories

After changing the location to

更改位置后

Configuration Properties -> VC++ Directories -> Include Directories

and adding the path to the DDK after $(IncludePath) everything worked fine.

并在 $(IncludePath) 之后添加到 DDK 的路径一切正常。

Juriy Petrochenkov was on the right track with his remark, so I rechecked where I have added the DDK directory to, and, lo and behold, it was the wrong one. Thank's Juriy!

Juriy Petrochenkov 的评论是正确的,所以我重新检查了我将 DDK 目录添加到的位置,瞧,这是错误的。谢谢朱莉!

回答by zhangjiadan

I have the same problem, you can copy sal.hfrom Microsoft Visual Studio 10.0\VC\includeto WinDDK\7600.16385.1\inc\api\and copy Microsoft Visual Studio 10.0\VC\include\CodeAnalysisto WinDDK\7600.16385.1\inc\api\.

我有同样的问题,您可以复制sal.hMicrosoft Visual Studio 10.0\VC\includeWinDDK\7600.16385.1\inc\api\并复制Microsoft Visual Studio 10.0\VC\include\CodeAnalysisWinDDK\7600.16385.1\inc\api\

回答by JasonE

I have found that my include directory was inheritting from parent or project defaults. The problem is that in VS2010 the Global options for include paths has been removed. After some searching, I found that the two files that contained these settings (From my previous install of VS) were in the following directory:

我发现我的包含目录继承自父级或项目默认值。问题是在 VS2010 中,包含路径的全局选项已被删除。经过一番搜索,我发现包含这些设置的两个文件(来自我之前安装的 VS)位于以下目录中:

C:\users\username\appdata\local\microsoft\msbuild\v4.0\

C:\users\username\appdata\local\microsoft\msbuild\v4.0\

The two files are:

这两个文件是:

  1. Microsoft.Cpp.Win32.user.props
  2. Microsoft.Cpp.x64.users.props
  1. Microsoft.Cpp.Win32.user.props
  2. Microsoft.Cpp.x64.users.props

Edit the IncludePath variable

编辑 IncludePath 变量

Remove the DDK path, saved the file, and restarted VS2010. This resolved my issue for all new projects.

删除DDK路径,保存文件,重启VS2010。这解决了我所有新项目的问题。

回答by user350091

Yes, changing the users.prop works, but how strange! You can't change this setting from a menu in Visual Studio and you can't overwrite it in the project properties. Even if you erase the setting just putting in $(IncludePath) it nevertheless uses the default path to the DDK.

是的,更改 users.prop 是有效的,但多么奇怪!您无法从 Visual Studio 中的菜单更改此设置,也无法在项目属性中覆盖它。即使您删除了仅放入 $(IncludePath) 的设置,它仍然会使用 DDK 的默认路径。

回答by Justin

or you can add, $(VSInstallDir)\VC\include\sal.hto the forced includes setting in your C++ advanced settings. This will force crtdef.hline #include <sal.h>effectively to #include "sal.h"but much less destructive. forcing it to use the current folder rather than the include system paths.

或者您可以添加$(VSInstallDir)\VC\include\sal.h到 C++ 高级设置中的强制包含设置。这将有效地强制crtdef.h线#include <sal.h>#include "sal.h"但破坏性要小得多。强制它使用当前文件夹而不是包含系统路径。

回答by user112771

After adding the /showincludes parameter I got the following result:

添加 /showincludes 参数后,我得到以下结果:

   1>  Note: including file: c:\testapp\stdafx.h
   1>  Note: including file:  c:\testapp\targetver.h
   1>  Note: including file:   C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\WinSDKVer.h
   1>  Note: including file:   C:\WinDDK01.18001\inc\api\SDKDDKVer.h
   1>  Note: including file:  C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h
   1>  Note: including file:   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\crtdefs.h
   1>  Note: including file:    C:\WinDDK01.18001\inc\api\sal.h
   1>  Note: including file:    C:\Program Files\Microsoft Visual Studio 10.0\VC\include\vadefs.h

That would make sense that for some reason it loads the two files from the DDK path and not the VS2010 include dir , if that is in fact the problem how do I tell it to use the correct path?

出于某种原因,它从 DDK 路径而不是 VS2010 include dir 加载两个文件是有道理的,如果这实际上是问题,我该如何告诉它使用正确的路径?

回答by Peter Cardona

Did you ever build the project with the prior version? stdafx.h is the standard precompiled header name for msvc projects. If you built with VS2008, it could have created the precompiled header and perhaps VS2010 is picking it up. (If you're not familiar, a precompiled header is build output generated by the compiler that's kept around to speed up compilation of header files the next time you build.)

你有没有用之前的版本构建过这个项目?stdafx.h 是 msvc 项目的标准预编译头名称。如果您使用 VS2008 构建,它可能已经创建了预编译头文件,并且 VS2010 可能会选择它。(如果您不熟悉,预编译头是由编译器生成的构建输出,它会保留在您下次构建时加速头文件的编译。)

I'd try a clean, then a manual inspection of the project directory (and build output directory if its in a non-obvious place), then a full build. If that didn't fix it, I'd turn off precompiled headers (at least temporarily) in the project settings and rebuild.

我会尝试清理,然后手动检查项目目录(如果它位于不明显的地方,则构建输出目录),然后进行完整构建。如果那没有解决它,我会在项目设置中关闭预编译头(至少暂时)并重建。