Get the App
SLTechnology News&Howtos  ›  Servers  › 

Install and configure the method of compiling C++ with VS Code under Ubuntu

Shulou Source: shulou.com Published: 2022-06-02 04:45:16 10月05日 Update

Install and configure VS Code to compile C++ under Ubuntu

Install VS Code

Sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-makesudo apt-get updatesudo apt-get install ubuntu-makesudo umake web visual-studio-code

Then press a to agree directly by default.

Install the plug-in

After opening VS Code, press crtl + shift + P to bring up the command line, and then search for Cellular commands to install the one developed by Microsoft itself.

You can also install the C++ Intellisense plug-in, which is used to automatically complete the code.

Configure launch.json and tasks.json

Note that VS Code can only open the folder where the source code is located, not directly open the source file, otherwise the following will not be possible!

After opening the folder where the source code is located, open the source code in that folder. Press F5 to select C++

Then the launch.json file is automatically generated. There are only two changes needed.

Set

"program": "enter program name, for example\ ${workspaceRoot} / a.out"

Change to

"program": "${workspaceRoot} / a.out"

Set

"cwd": "\ ${workspaceRoot}"

Change to

"cwd": "${workspaceRoot}"

Complete launch.json

{"version": "0.2.0", "configurations": [{"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceRoot} / a.out", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [] "externalConsole": true, "MIMode": "gdb", "setupCommands": [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": true}]}

Then, call up the command line, type Task Runner, and select others

Tasks.json will be automatically generated at this point

Put one of them

"command": "echo"

Change to

"command": "Gmail +"

Set

"args": ["Hello World"]

Change to

"args": ["- g", "${workspaceRoot} / main.cpp"]

Note that the main.cpp here is the same as the source name of your current path.

Complete tasks.json

{/ / See https://go.microsoft.com/fwlink/?LinkId=733558 / / for the documentation about the tasks.json format "version": "0.1.0", "command": "isShellCommand +", "isShellCommand": true, "args": ["- g", "${workspaceRoot} / main.cpp"], "showOutput": "always"}

Run the test

Write a random code

# includeusing namespace std;int main () {cout

Tags: Files folders source code commands runs configurations codes commands locations plug-ins terminals automatic generation generation output selection compilation consistency flash two content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Redmi MySQL OPPO Reno Apple