微软的Visual Studio Code编辑器非常不错,但它没有默认支持构建C++项目的功能。
我该如何配置才能实现此功能?
微软的Visual Studio Code编辑器非常不错,但它没有默认支持构建C++项目的功能。
我该如何配置才能实现此功能?
如果您的项目有CMake配置,那么设置VSCode就非常简单,例如按照以下方式设置tasks.json
:
{
"version": "0.1.0",
"command": "sh",
"isShellCommand": true,
"args": ["-c"],
"showOutput": "always",
"suppressTaskName": true,
"options": {
"cwd": "${workspaceRoot}/build"
},
"tasks": [
{
"taskName": "cmake",
"args": ["cmake ."]
},
{
"taskName": "make",
"args" : ["make"],
"isBuildCommand": true,
"problemMatcher": {
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
build
的文件夹,其中包含CMake配置。problemMatcher
是用于 clang
-builds 的设置。如果要使用GCC,我认为您需要将 fileLocation
更改为 relative
,但我尚未测试过。按下Ctrl+,,然后打开设置菜单,选择Extensions>Run Code Configuration,滚动到其属性并找到Edit in settings.json,单击它并将以下代码添加到其中:
{
"code-runner.runInTerminal": true
}
微软现在推出了C/C++语言扩展。您可以通过进入“快速打开”(Ctrl+p)并输入以下内容来安装:
ext install cpptools
您可以在这里阅读相关内容:
https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/
这是非常基础的,截至2016年5月。