更改 obj 文件的构建路径

Change the build path for obj files

我最近下载了用于 vs 代码的 C/C++ 扩展,然后 tutorial 为 windows 设置它。我设法弄清楚如何更改可执行文件的构建路径,但我无法弄清楚如何更改 .objvc140.pdb 文件的构建路径。

这是我希望在构建和 运行 程序后最终得到的目录结构:

现在 .objvc140.pdb 文件最终位于我目录的根目录中,但我想将它们放在 obj 文件夹下,如上所示。

这是我当前的 tasks.json 文件:

{
 "version": "2.0.0",
 "tasks": [
    {
        "type": "shell",
        "label": "C/C++: cl.exe build active file",
        "command": "cl.exe",
        "args": [
            "/Zi",
            "/EHsc",
            "/Fe:",
            "${workspaceFolder}\bin\debug\${fileBasenameNoExtension}.exe",
            "${file}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$msCompile"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
     }
  ]
}

经过 command line arguments for the msvc compiler

我找到了问题的解决方案

我必须添加一个 /Fd and a /Fo 参数来正确配置 pdbobj 文件的构建路径。

如果有人对 tasks.json 感兴趣,这里是:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${workspaceFolder}\bin\debug\${fileBasenameNoExtension}.exe",
                "/Fd:",
                "${workspaceFolder}\obj\debug\vc140.pdb",
                "/Fo:",
                "${workspaceFolder}\obj\debug\${fileBasenameNoExtension}.obj",
                "${file}"
                
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}