0
点赞
收藏
分享

微信扫一扫

Ubuntu下用VSCODE搭建的C语言环境

J简文 2022-03-30 阅读 62

目录

GCC交叉编译环境的配置

  1. 安装gcc编译器(C++为g++)sudo apt-get install gcc
  2. 检测是否安装成功gcc --version

VSCODE环境配置

运行

  1. 下载插件: C/C++ Extension Pack
  2. 下载插件: Code Runner
    这样就可以简单的编译运行一个简单的C文件了

调试

  1. 点击左边的调试按钮,然后点击调试,这时候它会自动生成.vscod文件,并且有aunch.json和tasks.json文件
  2. 将下列代码复制到launch.json内并保存
{
    "version": "2.0.0",
    "tasks": [{
            "label": "compile",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

  1. 将下列代码复制到tasks.json中去。
{
    "version": "2.0.0",
    "tasks": [{
            "label": "compile",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": [
                    "relative",
                    "${workspaceRoot}"
                ],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

注:如果需要是c语言也就是gcc将下面的command项由g++改为gcc

多文件编译

  1. 点击CodeRunner设置,扩展设置
  2. 找到Code-runner: Executor Map选项,点击设置,将设置复制为json文本
  3. 点击在settings.json中编辑
  4. 打开settings.json文件,空行处粘贴
  5. 找到"c" “cpp"选项将”$fileName"分别修改成*.c和*.cpp

参考资料

菜鸟入门之一:在Ubuntu18.04下利用VS code编写C语言的配置
Linux/Ubuntu中Vs Code配置C++/C环境
VsCode配置成编译多文件(C/C++)

举报

相关推荐

0 条评论