web123456

Problems and solutions for compiling C++ (cl command) in Windows native cmd window

  Objects applicable to this article:  Windows Under the operating system,It has been successfully installed Visual studio,And hopefully Windows systemNative cmd windowpeople who compile C++. The example operating system in this article is Windows 10 1703 64-bit, and the example VS version is Visual Studio 2017 Community.

 Note: The following example paths may vary slightly across different operating systems or different VS versions.


Recently, when I was getting started with C++, a series of problems occurred when compiling C++ in the native cmd window. After searching, we will solve the problem. Now summarize the problem and solutions below.

  /*

*It's too long to read the version:

*The problems that arise are basically that the system variables in the environment variable are not operated, and the following paths are just edited into the environment variables.

  */


 1. ‘cl’ is not an internal or external command, nor is it a runnable program or batch file

The above error indicates that the system cannot find this file.

This file is located in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64 (Again reminder, the path shown may vary for different operating systems or different VS versions).

The solution is to right-click this computer and select "Properties", "Advanced System Settings", and "Environment Variables". Find the variable path in System Variables below, select Edit, and Create New. Just add the above path to this variable.


  2. "fatal error C1034: iostream: Excluding path set" or "fatal error C1083: Unable to open include file: "": No such file or directory"

The above error indicates that the system cannot find the iostream or this file. The header files of C++ are saved in the following directories.

The solution is to right-click this computer and select "Properties", "Advanced System Settings", and "Environment Variables". Select the variable INCLUDE in the "System Variable" below. If this variable is not available, select "New". The variable is named "INCLUDE". The variable value is listed below:

      C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\include

      C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\shared

      C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt

      C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um

      C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\winrt

      Note: The paths are separated by English semicolons.


 3. fatal error LNK1104: Fatal error file "" cannot be opened

The above problem indicates that the system cannot find the .lib file. The paths to these files are listed below.

The solution is to right-click this computer and select "Properties", "Advanced System Settings", and "Environment Variables". Select the variable LIB in the "System Variable" below. If there is no such variable, select "New", the variable is named "LIB", and the variable values ​​are listed below:

      C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\lib\x64

      C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\ucrt\x64

      C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x64

     Note: The paths are separated by English semicolons.


If all the above three steps are completed, problems still occur, possible situations and solutions are:

1. Check that all the above paths are saved under the correct variable name;

2. Restart the cmd window and try again;

3. The system adds the other path to 32/64 bits.


If this article does not solve your problem, please leave a question in the comments for discussion, thank you.