With MSVC build tools setup with vscode, how to have the *.obj and .pdb files be generated in separated directory?

52 Views Asked by At

Currently they generate under workspace folder. The built binary successfully builds in build folder with my tasks.json but how do I achieve the same for the obj and .pdb files. I tried doing that with /Fo and /Fd but it does not work as in with /Fo it complains about that the obj directory is not found and with /Fd it shows "fatal error C1041: cannot open program database 'C:\Projects\learningcpp\obj\vc140.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS"

My tasks.json file:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: cl.exe build active file",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/sdl",
                "/nologo",
                "/Fe${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
                "/Fd${workspaceFolder}\\obj\\vc140.pdb",
                "/Fo${workspaceFolder}\\obj\\${fileBasenameNoExtension}.obj",
                "${file}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

I tried adding the /Fo and /Fd arguments. They resulted in errors. I did successfully made it so the generated binary is created in the build directory.

0

There are 0 best solutions below