【问题标题】:How to prepare/configure development environment for C++ projects in Visual Code Editor?如何在 Visual Code Editor 中为 C++ 项目准备/配置开发环境?
【发布时间】:2015-10-13 09:04:06
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案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            
           }         
        ]
      }
      

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

    您可以通过转到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" } 
    ]
    

    【讨论】:

      【解决方案2】:

      在 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

      【讨论】:

        猜你喜欢
        • 2018-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-11
        • 2019-06-03
        • 2020-01-26
        • 2015-07-15
        相关资源
        最近更新 更多