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

25 div+css programming tips and tricks

1. The ul tag has a padding value by default in M...

How to maintain a long connection when using nginx reverse proxy

· 【Scene description】 After HTTP1.1, the HTTP pro...

Methods and steps to build nginx file server based on docker

1. Create a new configuration file docker_nginx.c...

How to configure virtual user login in vsftpd

yum install vsftpd [root@localhost etc]# yum -y i...

Common symbols in Unicode

Unicode is a character encoding scheme developed ...

VMwarea virtual machine installation win7 operating system tutorial diagram

The installation process of VMwarea will not be d...

Example of implementing the skeleton screen of WeChat applet

Table of contents What is a skeleton screen How t...

Understanding and usage scenarios of ES6 extension operators

Table of contents 1. Replace the apply method, ge...

vue+element custom query component

This article mainly introduces the Vue project. O...

Do you know how to use vue-cropper to crop pictures in vue?

Table of contents 1. Installation: 2. Use: 3. Bui...

Use Shell scripts to batch start and stop Docker services

Table of contents Start Docker Stop Docker Python...

Nginx high concurrency optimization practice

1. Necessity of Tuning​ I have always been reluct...

Use of MySQL truncate table statement

The Truncate table statement is used to delete/tr...