如何在Visual Code Editor中为C ++项目准备/配置开发环境?

时间:2015-10-13 09:04:07

标签: c++ debugging compilation visual-studio-code

我正在使用nodejs和可视代码编辑器处理JavaScript项目。我想知道是否可以为C ++项目配置这么好的代码编辑器。

我想链接调试器并制作一些热键来构建项目的debug/release版本。

C ++项目是否可能,我应该为它做什么/阅读?

2 个答案:

答案 0 :(得分:1)

  

我想链接调试器

目前无法使用公共扩展程序API。我预计它会在今年11月或12月到来。

  

我想[...]制作一些热键来构建项目的调试/发布版本。

如果您只想在工作区中编译一个项目,则可以立即执行此操作。 这是怎么做的:

  • 在VSCode中打开项目的根文件夹(这是您的工作区)
  • 在工作区中放置一个批处理/ shell脚本,该脚本接受值为release/debug的参数,并根据传递的参数值在发布或调试模式下编译项目
  • 如果工作区中没有.vscode目录,则在您自己的
  • 上创建
  • 将文件tasks.json添加到包含此内容的文件夹中:

    {
      "version": "0.1.0",
      "command": "${workspaceRoot}/CompileProject.bat",
      "tasks": [
         {
              "taskName": "Compile debug build",
              "args": [
                "debug" 
              ],
              "isTestCommand": true            
         },
         {
              "taskName": "Compile release build",
              "args": [
                "release" 
              ],
              "isBuildCommand": true            
         }         
      ]
    }
    

您可以使用Compile debug build触发CTRL + Shift + TCompile release build触发CTRL + Shift + B

您可以转到File -> Preferences -> Keyboard Shortcuts更改键绑定,并为命令workbench.action.tasks.testworkbench.action.tasks.build定义首选快捷方式。 例如:

[
    { "key": "f5",          "command": "workbench.action.tasks.test" },
    { "key": "f6",          "command": "workbench.action.tasks.build" } 
]

答案 1 :(得分:0)

在tasks.json文件中使用以下内容,根据需要更改“helloworld”字符串。

// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

{
    "version": "0.1.0",
    "command": "gcc",
    "args": ["-Wall", "helloWorld.c", "-o", "helloWorld"],
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    }
}

编辑:这需要gcc在路径上可用。可以使用Ctrl + shift + b触发构建。 调试器尚不可用AFAIK