[C++ study notes] Nine, vscode configuration C++ environment

1 Configuration instructions

For visual studio, the compilation is extremely slow. When it is not some large-scale projects, it is also slow to compile a few broken files. This time reflects the power of vscode.

Vscode is just a text compiler, and with some plug-ins, it can also completely compile and debug c++ related codes.
Use the system win10/ubuntu

  • VSCode:
  • cmake
  • compiler/debugger

2 cmake

From Baidu Encyclopedia:
CMake is a cross-platform installation (compilation) tool, which can describe the installation (compilation process) of all platforms with simple sentences. It can output various makefiles or project files, and can test the C++ features supported by the compiler, similar to automake under UNIX. It's just that the configuration file of CMake is named CMakeLists.txt. Cmake does not directly construct the final software, but generates standard construction files (such as Unix Makefile or Windows Visual C++ projects/workspaces), and then uses them in the usual construction mode. This allows a developer familiar with an integrated development environment (IDE) to build his software in a standard way, and this ability to use each platform's native build system is what differentiates CMake from other similar systems such as SCons.
Direct download from win10 official website https://cmake.org/
linux system

sudo apt install cmake

Check whether cmake is successfully installed and the environment variables are configured correctly.

cmake --version
会打印如下的内容
cmake version 3.26.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).

3 VSCode

VSCode official download address: https://code.visualstudio.com/
Then install c++ and cmake related support plug-ins
insert image description here

4 configuration

Compiler and debugger can use MinGW or directly download and use the compiler in visual studio (when downloading visual studio, it will be added to the environment variable by itself)
to create CMakeLists.txt and main.cpp files and
add the following content to the CMakeLists.txt file:

# cmake最低版本需求
cmake_minimum_required(VERSION 3.10)

# 工程名称
project (demo)

# 设置C标准还是C++标准
set(CMAKE_C_STANDARD 11)

add_executable(demo
        main.cpp)

insert image description here
ctrl + shift + p to open the command terminal and enter:

CMake: select a Kit
insert image description here
to select the corresponding kit.
Use the gcc tool under linux

After configuring cmake, make sure there is no error message. Compile shortcut key f5, debug f7
insert image description here
How to break the debug point, you have to install this plugin
@category:debuggers CMake
This is the cmake tool kits configuration file. You can use any kit above
C:\Users\Administrator\AppData\Local\CMakeTools\cmake-tools-kits.json

[
  {
    "name": "GCC 7.3.0 x86_64-w64-mingw32",
    "compilers": {
      "C": "D:\\Qt\\Tools\\mingw730_64\\bin\\gcc.exe",
      "CXX": "D:\\Qt\\Tools\\mingw730_64\\bin\\g++.exe"
    },
    "preferredGenerator": {
      "name": "MinGW Makefiles"
    },
    "environmentVariables": {
      "CMT_MINGW_PATH": "D:\\Qt\\Tools\\mingw730_64\\bin"
    }
  },
  {
    "name": "Visual Studio Community 2022 Release - amd64",
    "visualStudio": "4ad9cc0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "host=x64"
    }
  },
  {
    "name": "Visual Studio Community 2022 Release - amd64_x86",
    "visualStudio": "4ad9cc0b",
    "visualStudioArchitecture": "x64",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "host=x64"
    }
  },
  {
    "name": "Visual Studio Community 2022 Release - x86",
    "visualStudio": "4ad9cc0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "win32",
      "toolset": "host=x86"
    }
  },
  {
    "name": "Visual Studio Community 2022 Release - x86_amd64",
    "visualStudio": "4ad9cc0b",
    "visualStudioArchitecture": "x86",
    "preferredGenerator": {
      "name": "Visual Studio 17 2022",
      "platform": "x64",
      "toolset": "host=x86"
    }
  },
  {
    "name": "gcc",
    "compilers": {
      "C": "D:\\VS\\IDE\\VC\\Tools\\MSVC\\14.35.32215\\bin\\Hostx86\\x86\\cl.exe",
      "CXX": "D:\\VS\\IDE\\VC\\Tools\\MSVC\\14.35.32215\\bin\\Hostx86\\x86\\cl.exe"
    }
  }
]

Guess you like

Origin blog.csdn.net/qq_38753749/article/details/129887507