Vscade modification exe file generation location

cause

When writing C language exercises today, I found that such a situation occurred in the vscade workspace:

The executable file generated by the program running is mixed with the source code. As an obsessive-compulsive disorder, how can I tolerate it "so presumptuous" and specially check a wave of Official documents Finally found a solution, which is right exe file location reset backward workspace file directory:

What about? Does it look more comfortable? emmm... OCD is very friendly. Let's show you how I solved it.

resolvent

Document establishment

Now close vscade, create a new folder on the desktop, and then drag it to the vscade icon to open it. This file is our workspace

After opening, we create a new folder Demo and a new file hello c. Enter the code for us to test later

#include <stdio.h>
int main()
{
    printf("Hello world");
    return 0;
}
copy

Click the debug button on the left - > create launch JSON file

Select C++(GDB/LLDB)

Select gcc Exe generate and debug activity files

Return to the workspace file directory and find that the generated vscode folder containing launch JSON and tasks JSON file. A brief introduction: tasks is used for compiling and launch is used for executing the compiled file. Details click here .

redirect

In order to make it convenient for everyone to modify, the document is directly given, and the modified position is marked with special marks. You can use Ctrl+F to search. You can simply delete the generated file content and copy the following corresponding file operations.

tasks.json

{
    "tasks": [
        {//Build configuration item
            "type":"shell",//Task type. Vscade directly passes the predefined variable escape resolution to the command; Shell - > open the shell first and then enter the command, so args will be parsed again through the shell
            "label": "C/C++: gcc.exe Generate active file",//Task name
            "command": "C:\\Program Files\\mingw64\\bin\\gcc.exe",//Local compiler path
            "args": [ //Contains parameters passed to gcc commands to implement specific functions
                "-g", //Build and debug related information
                "${file}", //Specifies that the compiled file is the current file
                "-o",//Specify the path and name of the output file
                "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe"//Modification exe file generation location
            ],
            "options": {
                "cwd": "C:\\Program Files\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {//It contains many task s and is classified as a group
                "kind": "build",//Table name this group task type is build
                "isDefault": true//Indicates that this task is the default task in this group
            },
            "detail": "Debugger generated tasks."
        }
    ],
    "version": "2.0.0"
}
copy

(1) Will command

"${fileDirname}\\${fileBasenameNoExtension}.exe"
copy

Replace with

"${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe"
copy

(2) Will command

"cwd": "${fileDirname}"
copy

Replace with

"cwd": "C:\\Program Files\\mingw64\\bin"
copy

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {//Include Debug configuration
            "name": "gcc.exe - Generate and debug activity files",//Configuration name
            "type": "cppdbg", //Configuration type, corresponding to the debugging function provided by cpptools
            "request": "launch", //Request configuration type, which can be start / attach type [launch/attach]
            "program": "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe",//Local path of program to be debugged
            "args": [], //Command line parameter passed to the program during program debugging, set to null value
            "stopAtEntry": false,//When it is changed to true, the program pauses and marks a breakpoint at the program entry position, that is, at main
            "cwd": "${fileDirname}", //The working directory when debugging the program, which represents the source code directory here
            "environment": [], //Environment variable, set to null
            "externalConsole": false, //true:cmd window; False: built in terminal output of vscade
            "MIMode": "gdb", //Specify the connected debugger, debugger ->gdb in minGW64
            "miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe", //Specify the path where the debugger is located. Note that it needs to be modified if the installation location is different. The interval is\
            "setupCommands": [
                {
                    "description": "by gdb Enable neat printing",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe Generate active file" //Before debugging, execute the tasks to be executed. Before debugging, compile the build name and tasks Consistent label of JSON
        }
    ]
}
copy

Will command

"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
copy

Replace with

"program": "${workspaceFolder}\\build\\${fileBasenameNoExtension}.exe",
copy

Code Runner

Click Edit in settings JSON opens the configuration item. Since there are many configuration files in the Code Runner, we can only modify the relevant parts

(1) Will command

"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 
copy

Replace with

"c": "cd $dir && gcc $fileName -o $workspaceRoot/build/$fileNameWithoutExt && $workspaceRoot/build/$fileNameWithoutExt",
copy

(2) Will command

"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 
copy

Replace with

"cpp": "cd $dir && g++ $fileName -o $workspaceRoot/build/$fileNameWithoutExt && $workspaceRoot/build/$fileNameWithoutExt", 
copy

Finally, create a new folder, build, in the workspace, as a sub item of the Test file to determine the file dependency.

test

Complete, OCD is very satisfied~~

Posted by daredevil88 on Fri, 03 Jun 2022 08:31:57 +0530