首页 > 系统相关 >ubuntu中用vscode

ubuntu中用vscode

时间:2022-10-08 14:12:09浏览次数:77  
标签:fileDirname vscode sudo 中用 C++ ++ gdb ubuntu

下载vscode

终端中输入code运行

输入sudo apt-get update

 

 sudo apt-get install gcc

 

 此报错解决方式:

sudo rm /var/lib/dpkg/lock-frontend

参考:

(40条消息) 成功解决E: 无法获得锁 /var/lib/dpkg/lock-frontend - open (11: 资源暂时不可用) E: 无法获取 dpkg 前端锁(/var/lib/dpkg/lock_余府的博客-CSDN博客_无法获取软件包后端的互斥锁

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++

标签:fileDirname,vscode,sudo,中用,C++,++,gdb,ubuntu
From: https://www.cnblogs.com/cangshiqian/p/16768768.html

相关文章