• <tfoot id='28cHh'></tfoot>
    1. <i id='28cHh'><tr id='28cHh'><dt id='28cHh'><q id='28cHh'><span id='28cHh'><b id='28cHh'><form id='28cHh'><ins id='28cHh'></ins><ul id='28cHh'></ul><sub id='28cHh'></sub></form><legend id='28cHh'></legend><bdo id='28cHh'><pre id='28cHh'><center id='28cHh'></center></pre></bdo></b><th id='28cHh'></th></span></q></dt></tr></i><div id='28cHh'><tfoot id='28cHh'></tfoot><dl id='28cHh'><fieldset id='28cHh'></fieldset></dl></div>

        <legend id='28cHh'><style id='28cHh'><dir id='28cHh'><q id='28cHh'></q></dir></style></legend>
        • <bdo id='28cHh'></bdo><ul id='28cHh'></ul>

        <small id='28cHh'></small><noframes id='28cHh'>

        无法使用 Visual Studio 2015 命令行工具编译和链接简单的 C++ 程序

        Unable to compile and link simple C++ program with Visual Studio 2015 command line tools(无法使用 Visual Studio 2015 命令行工具编译和链接简单的 C++ 程序)

        <small id='zkHQ6'></small><noframes id='zkHQ6'>

              <tfoot id='zkHQ6'></tfoot>
            • <i id='zkHQ6'><tr id='zkHQ6'><dt id='zkHQ6'><q id='zkHQ6'><span id='zkHQ6'><b id='zkHQ6'><form id='zkHQ6'><ins id='zkHQ6'></ins><ul id='zkHQ6'></ul><sub id='zkHQ6'></sub></form><legend id='zkHQ6'></legend><bdo id='zkHQ6'><pre id='zkHQ6'><center id='zkHQ6'></center></pre></bdo></b><th id='zkHQ6'></th></span></q></dt></tr></i><div id='zkHQ6'><tfoot id='zkHQ6'></tfoot><dl id='zkHQ6'><fieldset id='zkHQ6'></fieldset></dl></div>

                <tbody id='zkHQ6'></tbody>

                <bdo id='zkHQ6'></bdo><ul id='zkHQ6'></ul>
                • <legend id='zkHQ6'><style id='zkHQ6'><dir id='zkHQ6'><q id='zkHQ6'></q></dir></style></legend>
                  本文介绍了无法使用 Visual Studio 2015 命令行工具编译和链接简单的 C++ 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 Visual Studio 2015 中,我无法再使用命令行工具编译和链接简单的 C++ 程序.

                  With Visual Studio 2015 I am no longer able to compile and link a simple C++ program using the command line tools.

                  考虑 main.cpp:

                  Consider main.cpp:

                  #include <stdlib.h>
                  int main() { return 0; }
                  

                  在以前的版本(例如 Visual Studio 2012)中,我能够轻松编译和链接 main.cpp:

                  In previous releases (for example Visual Studio 2012) I was able to compile and link main.cpp easily:

                  C:Userskirchersrc	est>cl main.cpp
                  Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x64
                  Copyright (C) Microsoft Corporation.  All rights reserved.
                  
                  main.cpp
                  Microsoft (R) Incremental Linker Version 11.00.61030.0
                  Copyright (C) Microsoft Corporation.  All rights reserved.
                  
                  /out:main.exe
                  main.obj
                  

                  大功告成.

                  但是,使用 Visual Studio 2015,我不再设置正确的 CRT 包含和库路径:

                  With Visual Studio 2015 however, I no longer have proper CRT include and library paths set:

                  C:Userskirchersrc	est>cl main.cpp
                  Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x64
                  Copyright (C) Microsoft Corporation.  All rights reserved.
                  
                  main.cpp
                  main.cpp(1): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory
                  

                  我了解 Microsoft 将 C 运行时作为新的 Windows 操作系统组件(通用 CRT)进行分发.

                  I understand that Microsoft distributes the C runtime as a new Windows operating system component, the Universal CRT.

                  如通用 CRT 简介,我应该使用以下 MSBuild 属性来找到合适的路径

                  As described in Introducing the Universal CRT, I should use following MSBuild properties to find the appropriate paths

                  $(UniversalCRT_IncludePath)
                  $(UniversalCRT_LibraryPath_x64)
                  

                  尽管如此,我如何获得适当的库并包含 devenv 或 MSBuild 以外的构建系统的路径?

                  Despite that, how do I get proper library and include paths for build systems other than devenv or MSBuild?

                  为了它:

                  C:Program Files (x86)Microsoft Visual Studio 14.0VC>set include
                  INCLUDE=C:Program Files (x86)Microsoft Visual Studio 14.0VCINCLUDE;C:Program Files (x86)Microsoft Visual Studio 14.0VCATLMFCINCLUDE;C:Program Files (x86)Windows Kits10includewdfucrt;C:Program Files (x86)Windows KitsNETFXSDK4.6includeum;C:Program Files (x86)Windows Kits10includewdfshared;C:Program Files (x86)Windows Kits10includewdfum;C:Program Files (x86)Windows Kits10includewdfwinrt;
                  
                  C:Program Files (x86)Microsoft Visual Studio 14.0VC>set lib
                  LIB=C:Program Files (x86)Microsoft Visual Studio 14.0VCLIBamd64;C:Program Files (x86)Microsoft Visual Studio 14.0VCATLMFCLIBamd64;C:Program Files (x86)Windows Kits10libwdfucrtx64;C:Program Files (x86)Windows KitsNETFXSDK4.6libumx64;C:Program Files (x86)Windows Kits10libwdfumx64;
                  LIBPATH=C:WindowsMicrosoft.NETFramework64v4.0.30319;C:Program Files (x86)Microsoft Visual Studio 14.0VCLIBamd64;C:Program Files (x86)Microsoft Visual Studio 14.0VCATLMFCLIBamd64;C:Program Files (x86)Windows Kits10UnionMetadata;C:Program Files (x86)Windows Kits10References;C:Program Files (x86)Windows Kits10ReferencesWindows.Foundation.UniversalApiContract1.0.0.0;C:Program Files (x86)Windows Kits10ReferencesWindows.Foundation.FoundationContract1.0.0.0;C:Program Files (x86)Windows Kits10Referencesindows.Networking.Connectivity.WwanContract1.0.0.0;C:Program Files (x86)Microsoft SDKsWindows Kits10ExtensionSDKsMicrosoft.VCLibs14.0ReferencesCommonConfiguration
                  eutral;
                  

                  推荐答案

                  包括环境变量的内容是个好主意.根据出现在那里的路径,您似乎安装了 Windows 驱动程序工具包,并且遇到了这个 连接上报告的问题.

                  Including the contents of the environment variables was a good idea. Based on the paths appearing there, it seems that you have the Windows Driver Kit installed and you're encountering this issue reported on Connect.

                  根据问题描述,WDK创建的wdf目录混淆了试图确定最新可用SDK版本的批处理文件.例如,代替

                  According to the description of the issue, the wdf directory created by the WDK confuses the batch file that tries to determine the latest SDK versions available. For example, instead of

                  C:Program Files (x86)Windows Kits10includewdfucrt
                  

                  INCLUDE 变量中,你应该有类似

                  in the INCLUDE variable, you should have something like

                  C:Program Files (x86)Windows Kits10include10.0.10150.0ucrt
                  

                  <小时>

                  地毯式轰炸"解决方案:卸载WDK,确保wdf目录消失,一切恢复正常.


                  The "carpet-bombing" solution: uninstall the WDK, make sure the wdf directories are gone, and things should return to normal.

                  如果这不是一个选项,这里有一个手术"解决方案:您需要编辑

                  If that's not an option, here's a "surgical" solution: you need to edit

                  "C:Program Files (x86)Microsoft Visual Studio 14.0Common7Toolsvcvarsqueryregistry.bat"
                  

                  (当然要先备份)

                  1. 查找以下两个标签:

                  :GetWindowsSdkDirHelper32
                  :GetWindowsSdkDirHelper64
                  

                  在每一个下面,你会发现以下一行:

                  Under each of them, you'll find the following line:

                  @REM Get windows 10 sdk version number
                  @if not "%WindowsSdkDir%"=="" @FOR /F "delims=" %%i IN ('dir "%WindowsSdkDir%include" /b /ad-h /on') DO @set WindowsSDKVersion=%%i
                  

                  改为:

                  @REM Get windows 10 sdk version number
                  @if not "%WindowsSdkDir%"=="" @FOR /F "delims=" %%i IN ('dir "%WindowsSdkDir%include" /b /ad-h /on') DO (
                     @if not "%%i"=="wdf" (
                        @set WindowsSDKVersion=%%i
                     )
                  )
                  

                  2. 查找以下两个标签:

                  :GetUniversalCRTSdkDirHelper32
                  :GetUniversalCRTSdkDirHelper64
                  

                  在每一个下,更改以下行:

                  Under each of them, change the following line:

                  @FOR /F "delims=" %%i IN ('dir "%UniversalCRTSdkDir%include" /b /ad-h /on') DO @SET UCRTVersion=%%i
                  

                  到:

                  @FOR /F "delims=" %%i IN ('dir "%UniversalCRTSdkDir%include" /b /ad-h /on') DO (
                     @if not "%%i"=="wdf" (
                        @SET UCRTVersion=%%i
                     )
                  )
                  

                  就是这样.如果有帮助,请告诉我.

                  That's it. Let me know if it helped.

                  请记住,这将完全跳过 wdf 目录.如果 WDK 命令提示安装脚本碰巧使用相同的 vcvarsqueryregistry.bat 批处理文件(我对此表示怀疑,但是...),那么它们将不再正常工作;在这种情况下,需要更多的黑客攻击才能为每个构建环境选择合适的批处理文件.

                  Keep in mind that this will skip the wdf directories altogether. If the WDK command prompt setup scripts happen to use the same vcvarsqueryregistry.bat batch file (I doubt it, but...), then they won't work correctly anymore; a bit more hacking will be needed in this case to select the proper batch file for each build environment.

                  这篇关于无法使用 Visual Studio 2015 命令行工具编译和链接简单的 C++ 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                    <tfoot id='cE7nB'></tfoot>
                  1. <i id='cE7nB'><tr id='cE7nB'><dt id='cE7nB'><q id='cE7nB'><span id='cE7nB'><b id='cE7nB'><form id='cE7nB'><ins id='cE7nB'></ins><ul id='cE7nB'></ul><sub id='cE7nB'></sub></form><legend id='cE7nB'></legend><bdo id='cE7nB'><pre id='cE7nB'><center id='cE7nB'></center></pre></bdo></b><th id='cE7nB'></th></span></q></dt></tr></i><div id='cE7nB'><tfoot id='cE7nB'></tfoot><dl id='cE7nB'><fieldset id='cE7nB'></fieldset></dl></div>

                  2. <legend id='cE7nB'><style id='cE7nB'><dir id='cE7nB'><q id='cE7nB'></q></dir></style></legend>

                    <small id='cE7nB'></small><noframes id='cE7nB'>

                          <tbody id='cE7nB'></tbody>
                          <bdo id='cE7nB'></bdo><ul id='cE7nB'></ul>