当前位置:网站首页>Configure vscode+cmake under win11

Configure vscode+cmake under win11

2022-06-10 08:51:00 Itchy heart

1. install vscode

This step , There are tutorials on the Internet .

2. download mingw-w64

mingw-w64 Software download

3. Download and install cmake

cmake Software download
win11 64 Bit system selection latest cmake Software .

 Insert picture description here
 Insert picture description here

 Insert picture description here
 Insert picture description here
 Insert picture description here

  • Whether to add environment variables , Here we choose “Add CMake to the system PATH for all users”
  • Whether to create a desktop shortcut icon , Depending on your situation , This is just to create desktop icons for easy use , It will not have a substantial impact on future use

Generally, it is installed in by default c disc , According to personal needs . I am going to cmake Installed in the D Plate .
 Insert picture description here
The following figure shows the final confirmation of installation .
 Insert picture description here
 Insert picture description here
 Insert picture description here

Then check whether the environment variable increases the running path of the software .
 Insert picture description here
Before installing the software , Check add environment variable . After installation , An environment variable is automatically added .
 Insert picture description here
Test for successful installation

cmake --version

 Insert picture description here

4. stay VScode Middle configuration CMake

  1. First , To be in Vscode Install in cmake plug-in unit . Shortcut key Shift+Ctrl+X, Search for “cmake" and ”cmake tools“, Installation .
     Insert picture description here
  • CMake The main functions of the plug-in are CMake Syntax highlighting 、 Automatic completion
  • CMake Tools The main function of is to combine VSCode IDE Use CMake This tool , For example, generate CMake project 、 structure CMake Items, etc.
  1. Shift+Ctrl+P open VSCode Command panel for , Then input cmake:q,VSCode Will automatically prompt according to the input , And then choose CMake: Quick Start
    Premise : Need to open a folder .
     Insert picture description here
     Insert picture description here

 Insert picture description here

Then choose the compiler that suits you (VSCode The compilers you installed will be listed for your choice . If you are cross compiling , Then you can configure your cross compiler here ), For the convenience of demonstration, we choose GCC 8.1.0:
 Insert picture description here
Then enter the project name as prompted :
 Insert picture description here
Then choose whether the project creates a library or an executable , For the convenience of demonstration, we choose the executable file Executable
 Insert picture description here
then VSCode Will generate a CMake project , As shown below :
 Insert picture description here

  • build The folder is cmake The output folder of the instruction
  • Default generated CMakeLists.txt and main.cpp file
    Running results :
     Insert picture description here

5. Compile the project

cd build
cmake ..

however VSCode Provides a more convenient way ( Click on the bottom Build):
 Insert picture description here
Or in VSCode From the command panel of the build command ( Input cmake after VSCode Will help you list all supported commands ):

 Insert picture description here

原网站

版权声明
本文为[Itchy heart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100843359840.html