Linux system VsCode configuration C/C++ environment

0. In this article, VsCode running on Windows 11 remotely connects to the Linux system through SSH

reference

Reference: Configure C/C++ environment in Linux system VS Code
Reference: Configure C/C++ environment in vscode (GCC on Linux, a day to read official documents~)

1. Install g++, gcc, gdb

Check whether g++, gcc, gdb are installed

// 打印版本信息,注意v是小写的
gcc -v
g++ -v
gdb -v

If the output
insert image description here
is output, it means
insert image description here
installation

sudo apt-get install build-essential

After installation, both g++ and gcc can be successfully installed, but the following error occurs in gdb.
insert image description here
At the same time, after entering the following command

apt install gdb

If the following error occurs
insert image description here
, you need to do the following

apt-get update
apt-get upgrade
apt-get install packagename 

2. VsCode settings

install plugin

  • C/C+//required
  • Code Runner//required
  • C/C++ Snippets // Suggestions, provide some commonly used C/C++ snippets
  • EPITECH C/C++ Headers // Suggestions, add headers (including author, creation and modification date, etc.) for C/C++ files, and add anti-duplication macros for .h header files
  • File Templates // Suggestions, file templates, you can add file templates yourself
  • GBKtoUTF8 // Suggestion, convert GBK encoded file to UTF-8
  • Include Autocomplete // suggestion, header file auto-completion
  • One Dark Pro // Suggestion, you can create a good-looking VS Code theme

Search for code runner run in terminal in the settings, tickexist

run

Select the compiler:
ctrl+shift+p to open the command panel, search for Configure Default Build Task.
insert image description here
I don't know the difference between these compilers. Both the first and second try can run the .cpp file

Note that **.cpp needs to be active when searching
insert image description here
Under the .vscode folder, the tasks.json file saves the settings for running the file.
insert image description here

debugging

Ctrl+shift+p opens the command panel and searches for Add Configuration.
insert image description here
Select the debugger
insert image description here
Under the .vscode folder, the launch.json file saves the settings of the debug file.
insert image description here

Finish

insert image description here
If you want to remove
[1] + Done “/usr/bin/gdb” --interpreter=…,
you can add an item to the configurations field in the launch.json file:

"miDebuggerArgs": "-q -ex quit; wait() { fg >/dev/null; }; /bin/gdb -q --interpreter=mi",

Guess you like

Origin blog.csdn.net/qq_42911863/article/details/125619397