menu 李昊天的个人博客
Linux 下 VSCode c/c++环境配置
725 浏览 | 2019-08-03 | 分类:Linux | 标签:程序安装,经验,VScode

切换中文

安装完成的VSCode是英文的,作为一个英文不好的中国人,我还是喜欢看中文的界面。

点击左侧的

会进入扩展商店

拓展商店中直接搜索Chinese 然后点击Install就行

安装完成后重启应用就会变成中文界面。

安装插件

Code Runner

安装完成后窗口菜单栏下面就会出来一个

当你的显示页面是一个程序源文件(单个文件,不是项目)时,点击这个按钮或者按ctrl+F5就可以直接运行这个程序,方便快捷。

点击齿轮,点击配置,然后把右侧的Run In Terminal勾上,就会在控制台显示运行结果

c/c++

必装的插件。

C++ Intellisense

C++的只能提示工具

C/C++ Clang Command Adapter

提供静态检测(Lint)

配置环境

主要是两个json文件

launch.json

点击调试,然后选择添加配置。会自动生成lanunch.json文件

这是我的配置,可以直接复制过去

要注意的就是

"program": "${workspaceFolder}/hello.out", //当前目录下编译后的可执行文件

`"preLaunchTask": "build"`

这里的hello.out应该是你生成的执行文件,而build 应该是你的tasks的lable

{
    // 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": "debug cpp",    //名称
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/hello.out",    //当前目录下编译后的可执行文件
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",    //表示当前目录
            "environment": [],
            "externalConsole": false, // 在vscode自带的终端中运行,不打开外部终端
            "MIMode": "gdb",    //用gdb来debug
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build" //执行lanuch之前运行的task
        }
    ]
}

tasks.json

按住ctrl+shift+p

输入tasks,选择configure Task

选择使用模板创建然后选others

就会生成tasks.json文件

仍旧可以直接拷贝

参数应该是自己的,多个文件编译,和在bash中写一样,也可以用makefile

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",     // task的名字
            "type": "shell",   
            "command": "g++",    //编译命令
            "args": [    //编译参数列表
                "hello.cpp",
                "-o",
                "hello.out"
            ]
        }
    ]
}

 c_cpp_properties.json

ctrl+shift+p 输入c/c++:Edit Configurations 选择这一项就可以创建一个c_cpp_properties.json文件

不用改动,我也贴出来我的配置

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

如果有自己的外链库也是添加到这里面。

知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

发表评论

email
web

全部评论 (暂无评论)

info 还没有任何评论,你来说两句呐!