下载vscode
终端中输入code运行
输入sudo apt-get update
sudo apt-get install gcc
此报错解决方式:
sudo rm /var/lib/dpkg/lock-frontend
参考:
sudo apt-get install g++
sudo apt-get install gdb
可通过
gcc -v
g++ -v
gdb -v
检验安装是否成功
在vscode中安装c++插件和code runner
tasks.json告诉vscode如何编译程序
在.vscode文件夹下新建tasks.json
写入如下代码:
{ "version": "2.0.0", "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: /usr/bin/g++" } ] }
launch.json 文件用于在 Visual Studio Code 中配置调试器
{ // 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": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }
launch.json中部分关键字说明:
program: 指带调试的程序,其值对应程序的路径。在这里设置为"${fileDirname}/${fileBasenameNoExtension}",在本案例中对应“helloworld/helloworld”.
stopAtEntry: 默认情况下,C++拓展不会向源代码添加任何断点,stopAtEntry 值设置为 false。 将stopAtEntry值更改为 true 将使调试器在开始调试时停止在 main 方法上。
参考:
详解Linux下使用vscode编译运行和调试C/C++ - 知乎 (zhihu.com)
(40条消息) Linux/Ubuntu中Vs Code配置C++/C环境_CS_Lee_的博客-CSDN博客_ubuntu vscode配置c++