VSCode+CMake+Clang+GCC environment construction tutorial under win10

VSCode+CMake+Clang+GCC environment construction tutorial under win10

I plan to use C/C++ to implement basic data structures and algorithms to prepare for the postgraduate entrance examination. Since I just want to implement algorithms and data structures, I don’t want to use VisualStudio. I think VSCode is good, so I found some tutorials online and configured the development environment according to my needs.

Install the software

CMake

CMake is a cross-platform automated build system that uses a file called CMakeLists.txt to describe the build process;

Download and install from the official website, easy to use;

Remember to add the bin files in the installation directory to the system environment variables. This can be checked during installation. If you check it, you don’t need to add it yourself.

Check whether the installation is successful:


MinGW

MinGW stands for Minimalist GNU For Windows. It is the product of porting GNU development tools to the Win32 platform and is a set of GNU tools on Windows. Simply put, MinGW is a compilation environment; equivalent to GCC under Linux;

Official website download link;

After installation, add the path of the bin folder in the installation directory to the environment variable:

Clang

A compiler similar to GCC, its goal is to kill GCC (I saw someone say so on the Internet).

Wikipedia:

Clang (pronounced /ˈklæŋ/ like the English word clang[1]) is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages. It uses LLVM as its backend, and starting from LLVM2.6, new versions are released together. Its goal is to provide a replacement for the GNU Compiler Collection (GCC), supporting most of the compilation settings of the GNU compiler as well as unofficial language extensions. The author is Chris Lattner, and the development was sponsored by Apple, and the source code is licensed under the BSD-like University of Illinois at Urbana-Champaign open source license.

It can be used in VSCode to provide smart prompts;

Download the official website

Fool-proof installation, after installation, add the path of the bin folder under the installation directory to the environment variable;


Install VSCode plugin

As shown in the figure, install the plug-in in the figure:

Create a new folder and start coding

main.cpp

#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
 int a = 89;
 int b = a++;
 char buf[10] ;
 cout << "a = " << a << endl;
 cout << "b = " << b << endl;
 cout << "Hello...";
 cin.get(); //Prevent screen flashing return 0;
}

CMakeList.txt

cmake_minimum_required(VERSION 3.11)

project(VSCode_Cpp_CMake)
# Code path aux_source_directory(.DIR_TOOT_SRCS)
# debug mode set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
# Generate an executable file add_executable(VSCode_Cpp_CMake ${DIR_TOOT_SRCS})

Configure c_cpp_properties.json

Keyboard press: ctrl+shift+p


{
 "configurations": [
  {
   "name": "CMake",
   "includePath": [
    "${workspaceFolder}/**"
   ],
   "defines": [
    "_DEBUG",
    "UNICODE",
    "_UNICODE"
   ],
   "windowsSdkVersion": "10.0.18362.0",
   "compilerPath": "C:/MinGW/bin/g++.exe", // Determine according to your own installation directory "cStandard": "c11",
   "cppStandard": "c++17",
   "intelliSenseMode": "clang-x64", // Note the modification, provide intelligent prompts "configurationProvider": "vector-of-bool.cmake-tools"
  }
 ],
 "version": 4
}

Configure CMake

Press shortcut key: ctrl+shift+p

Follow the steps below:



After the operation is completed here, you can compile and generate an exe file:


Configure the debug files launch.json and task.json

Use gdb for debugging.

Shortcut: F5 -> C++ (GDB/LLDB) -> g++.exe build and debug actvive file

vscode will automatically generate a default launch.json and task.json

Edit launch.json and task.json, and note that all commented areas need to be modified;

task.json

{
 "tasks": [
  {
   "type": "shell",
   "label": "cmake build active file", // Task name "command": "cmake --build ${workspaceFolder}\\build --config Debug --target all -- -j 10", // CMake instructions "args": [
   ], // Command parameters "options": {
    "cwd": "C:/MinGW/bin"
   }
  }
 ],
 "version": "2.0.0"
}

launch.json

{
 // Use IntelliSense to learn about possible attributes.
 // Hover to view descriptions of existing attributes.
 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [
  {
   "name": "(gdb) Launch", // default: g++.exe build and debug active file
   "type": "cppdbg",
   "request": "launch",
   "program": "${workspaceFolder}\\build\\Demo.exe", // The path where the executable file is located, Demo= is replaced with your own item "args": [],
   "stopAtEntry": false,
   "cwd": "${workspaceFolder}",
   "environment": [],
   "externalConsole": true, // Display an independent console window "MIMode": "gdb",
   "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
   "setupCommands": [
    {
     "description": "Enable pretty-printing for gdb",
     "text": "-enable-pretty-printing",
     "ignoreFailures": true
    }
   ],
   "preLaunchTask": "cmake build active file" // Execute cmake compilation task, defined in task.json}
 ]
}

Compiling and debugging

Compile shortcut key: F7
Debug shortcut key: F5

Summarize

The above is the tutorial diagram of VSCode+CMake+Clang+GCC environment construction under win10 introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time @

You may also be interested in:
  • Steps to build a TensorFlow+VScode development environment from scratch (picture and text)
  • Detailed explanation of the Anaconda + vscode + pytorch environment construction process
  • Detailed explanation of the solutions to the problems encountered in setting up the VScode editor vue environment
  • How to use Pico to flash Micropython firmware and configure VsCode development environment

<<:  Vue uses custom instructions to add watermarks to the bottom of the page

>>:  Database SQL statement optimization

Recommend

How to quickly install RabbitMQ in Docker

1. Get the image #Specify the version that includ...

Detailed steps to install Mysql5.7.19 using yum on Centos7

There is no mysql by default in the yum source of...

mysql8.0.23 msi installation super detailed tutorial

1. Download and install MySql Download MySql data...

5 common scenarios and examples of JavaScript destructuring assignment

Table of contents Preface 1. Extract data 2. Alia...

Application of HTML and CSS in Flash

Application of HTML and CSS in Flash: I accidental...

CSS3 timeline animation

Achieve results html <h2>CSS3 Timeline</...

Use xshell to connect to the Linux server

Benefits of using xshell to connect to Linux We c...

Tutorial diagram of installing TomCat in Windows 10

Install TomCat on Windows This article will intro...

The implementation principle of Mysql master-slave synchronization

1. What is MySQL master-slave synchronization? Wh...

Detailed explanation of react setState

Table of contents Is setState synchronous or asyn...