900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器

【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器

时间:2019-08-12 16:49:59

相关推荐

【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器

文章目录

一、创建 tasks.json 编译器构建配置文件二、tasks.json 编译器构建配置文件分析

可以参考官方提供的文档 :/docs/cpp/config-linux

使用 VSCode 开发 C/C++ 程序 , 涉及到 333 个配置文件 :

① tasks.json :编译器构建 配置文件 ;

② launch.json :调试器设置 配置文件 ;

③ c_cpp_properties.json :编译器路径和智能代码提示 配置文件 ;

下面开始逐个 生成 上述配置文件 ;

一、创建 tasks.json 编译器构建配置文件

tasks.json 编译器构建配置文件 , 用于告诉 VSCode 如何去编译这个程序 ;

菜单栏选择 " 终端 / 配置默认生成任务 " ,

在弹出的对话框中 , 选择第 222 项 , " C/C++:g++ 生成活动文件 " 选项 ;

点击该选项 , 即可在 .vscode 目录中生成 tasks.json 文件 ;

文件内容如下 :

{"version": "2.0.0","tasks": [{"type": "cppbuild","label": "C/C++: g++ 生成活动文件","command": "/usr/bin/g++","args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "编译器: /usr/bin/g++"}]}

二、tasks.json 编译器构建配置文件分析

"label": "C/C++: g++ 生成活动文件",是编译 C/C++ 任务名称 , 该任务名称可以自定义 ;

"command": "/usr/bin/g++",中的 command 配置 , 是指定编译器 , 一般是 gcc 或者 g++ 编译器 ;

"args"数组 , 配置的是 command 指定的编译器后的编译选项 ;

"args": ["-fdiagnostics-color=always","-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],

"group"中的"isDefault": true指的是 , 使用 Ctrl + Shift + B 快捷键可以运行该任务 , 如果设置为 false , 需要从终端菜单中 , 选择 " 运行任务 " 来编译运行程序 ;

"group": {"kind": "build","isDefault": true},

【开发环境】Ubuntu 中使用 VSCode 开发 C/C++ ④ ( 创建 tasks.json 编译器构建配置文件 | tasks.json 编译器构建配置文件分析 )

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。