C++ VS2015 cl 在命令行上构建时找不到 CRT 库(stdio.h、ctype.h 等)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31862627/
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-28 14:02:20  来源:igfitidea点击:

VS2015 cl Can't find CRT libs (stdio.h, ctype.h etc.) when building on command line

c++visual-studio-2015

提问by Nilay Kothari

  • I have installed the latest VS2015 Professional version.
  • Opened the Visual Studio command prompt and ran vcvars32.bat
  • wrote a simple helloworld.cpp program (includes stdio.h and prints "hello world")
  • tried cl helloworld.cpp
  • 我已经安装了最新的 VS2015 专业版。
  • 打开 Visual Studio 命令提示符并运行 vcvars32.bat
  • 编写了一个简单的 helloworld.cpp 程序(包括 stdio.h 并打印“hello world”)
  • 试过cl helloworld.cpp

I get the following error:

我收到以下错误:

c:\test>cl helloworld.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

helloworld.cpp
helloworld.cpp(1): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory

The include paths set by the vcvars32.bat are:

由 vcvars32.bat 设置的包含路径是:

INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\include\wdf\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK.6\include\um;C:\Program Files (x86)\Windows Kits\include\wdf\shared;C:\Program Files (x86)\Windows Kits\include\wdf\um;C:\Program Files (x86)\Windows Kits\include\wdf\winrt;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\include\wdf\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK.6\include\um;C:\Program Files (x86)\Windows Kits\include\wdf\shared;C:\Program Files (x86)\Windows Kits\include\wdf\um;C:\Program Files (x86)\Windows Kits\include\wdf\winrt;

Note that the paths in the environment variable are "C:\Program Files (x86)\Windows Kits\10\include\wdf\winrt;" etc. However, the actual location of the files is C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\winrt;

注意环境变量中的路径是“ C:\Program Files (x86)\Windows Kits\10\include\ wdf\winrt;”等,但是文件的实际位置是C:\Program Files (x86) \Windows 工具包\10\include\ 10.0.10240.0\winrt;

Am I doing something wrong here? Any help greatly appreciated.

我在这里做错了吗?非常感谢任何帮助。

p.s. My real purpose is to build the boost 1.58 library (but it suffers from the same issue as above, so first wanted to isolate the problem).

ps 我的真正目的是构建 boost 1.58 库(但它遇到与上述相同的问题,所以首先想隔离问题)。

p.p.s. I noticed the following environment variables. But I'm unable to change them.

pps 我注意到以下环境变量。但我无法改变它们。

WindowsSDKLibVersion=wdf\
WindowsSDKVersion=wdf\

回答by AhmedBM

If you have WDK (Windows Driver Kit - 10.0.26639) installed you will encounter this issue as the include paths are overwritten by the WDK. To get this to work, you must uninstall the WDK and it should work.

如果您安装了 WDK(Windows 驱动程序工具包 - 10.0.26639),您将遇到此问题,因为 WDK 会覆盖包含路径。要使其正常工作,您必须卸载 WDK 并且它应该可以工作。

Take a look at the Microsoft Connect issue - https://connect.microsoft.com/VisualStudio/feedback/details/1610302/universalcrt-detection-breaks-when-windows-driver-kit-is-installed

看看 Microsoft Connect 问题 - https://connect.microsoft.com/VisualStudio/feedback/details/1610302/universalcrt-detection-breaks-when-windows-driver-kit-is-installed

回答by ???

In my case, I added these paths to the additional include path:

就我而言,我将这些路径添加到附加的包含路径中:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\Include\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\winrt;$(IncludePath)

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include;C:\Program Files (x86)\Windows Kits\ 10\Include\10.0.10586.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6\Include\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\共享;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\winrt;$(IncludePath)

and added these paths to the additional lib path:

并将这些路径添加到额外的 lib 路径中:

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x86;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86;$(LibraryPath)

C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x86;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\ucrt\x86;$(库路径)

回答by zwcloud

I ran into a similar problem on VS2017 (15.5.5) when building VC++ projects against Windows SDK 8.1:

在针对 Windows SDK 8.1 构建 VC++ 项目时,我在 VS2017 (15.5.5) 上遇到了类似的问题:

C1083 Cannot open include file: 'assert.h': No such file or directory

C1083 无法打开包含文件:'assert.h':没有那个文件或目录

Checking Windows 8.1 SDK and UCRT SDKin the VS installer solved the problem. Windows 8.1 SDK and UCRT SDK

检查Windows 8.1 SDK and UCRT SDKVS 安装程序解决了这个问题。 Windows 8.1 SDK 和 UCRT SDK