【问题标题】:match files .c on tasks.json to compile匹配 tasks.json 上的文件 .c 进行编译
【发布时间】:2022-11-28 12:21:15
【问题描述】:

我在 vscode 上使用微软扩展来编译 C,问题是,只有一个文件 .c,好的,但是当我包含一些库时,比如 conio.c,我需要手动告诉编译这个文件太把名字tasks.json 中的文件,我想自动执行此操作,但我无法在 tasks.json 中添加任何“模式”,而且我不知道 .json 是否运行正则表达式,在此先感谢!基本上我想匹配我在主程序中使用的所有 .c。

    {
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: gcc.exe arquivo de build ativo",
      "command": "gcc",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}"  ---add name of file to here compile---,
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Tarefa gerada pelo Depurador."
    }
  ],
  "version": "2.0.0"
}

【问题讨论】:

  • 如果您使用超过 1 个 .c 文件,请使用构建工具、Make、CMake、MSBuild 等,这是防止为每个构建重新编译所有内容的原因
  • 抱歉,我没听懂,也许是因为对这个话题缺乏认识,你能详细解释一下吗?感谢你的回答
  • 在网络上搜索不同的工具,您将获得 1000 多次点击以学习,有一个用于 VSC 的 CMake 扩展
  • 我记得我修复过一次,但不记得了,只使用了 tasks.json
  • 如果有人可以帮助我,我将不胜感激

标签: c json visual-studio-code gcc


【解决方案1】:
{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: gcc.exe arquivo de build ativo",
      "command": "gcc",
      "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${fileDirname}\**.c",
        "${fileDirname}\**.h",
        "-o",
        "${fileDirname}\bin\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "Tarefa gerada pelo Depurador."
    }
  ],
  "version": "2.0.0"
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多