在windows下使用Vscode用CMake..命令编译源代码时候遇到的问题之解决办法

        由于我在windows下用Vscode总是不记得如何deal这个错误,因此今天就用这篇博客记录下来!

        在windows的Vscode这个IDE下,打开终端,输入命令行:

C:\Users\11602\Desktop\test\build> cmake ..

        报错

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_C_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.  To fix this problem, run cmake from the
  Visual Studio Command Prompt (vcvarsall.bat).

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_CXX_COMPILER:


  is not a full path and was not found in the PATH.

  To use the NMake generator with Visual C++, cmake must be run from a shell
  that can use the compiler cl from the command line.  This environment is
  unable to invoke the cl compiler.  To fix this problem, run cmake from the
  Visual Studio Command Prompt (vcvarsall.bat).

        原因:我没有选择GCC作为我的编译器!(因为我windows下还有别的VS的编译器)

        deal办法

        ①先在Vscode下用键盘按下ctrl + shift + p,再选择CMake:Configure

在windows下使用Vscode用CMake..命令编译源代码时候遇到的问题之解决办法_第1张图片

        ②选择GCC作为我的编译器

在windows下使用Vscode用CMake..命令编译源代码时候遇到的问题之解决办法_第2张图片

         ③最后再用CMake..和mingw命令(windows)编译代码即可成功运行!

        (linux下则是用CMake..和make命令(linux)配合来编译代码的)

在windows下使用Vscode用CMake..命令编译源代码时候遇到的问题之解决办法_第3张图片

在linxu,下

出现问题:

make: *** No targets specified and no makefile found.  Stop.

原因:也是因为没有在Vscode下设置gcc为默认编译器!(同windows下的问题)

deal方法:按照上述步骤,ctrl + shift + p ,然后输入cmake configure ,然后选择gcc作为编译器即可!

你可能感兴趣的:(Linux下cpp开发,vscode,windows,c++)