The error message "the prelaunchtask 'c/c++: clang build active file' terminated with exit code -1" typically occurs when there's an issue with the prelaunch task configuration in a C/C++ development environment, such as Visual Studio Code.
To resolve this error, follow these steps:
Here's an sample of how the corrected task configuration might look:
{
"version": "2.0.0",
"tasks": [
{
"label": "c/c++: clang build active file",
"type": "shell",
"command": "clang",
"args": ["${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.out"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
You should be able to resolve the error and successfully build your C/C++ files in Visual Studio Code.
The error message "The preLaunchTask 'C/C++: g++.exe build active file' terminated with exit code 1" typically occurs when there's an issue with the preLaunchTask configuration in a C/C++ development environment.
To resolve this error, follow these steps:
Here's an sample of how the corrected task configuration look like below:
{
"version": "2.0.0",
"tasks": [
{
"label": "C/C++: g++.exe build active file",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"detail": "Generated by vscode-cpptools"
}
]
}
In our case, we encountered a similar issue and found a workaround that resolved it.
We deleted the .vscode folder, which is automatically generated the first time you debug in Visual Studio Code.
After deleting the .vscode folder, we attempted to debug again by pressing F5 or selecting "Debug C/C++ File" from the top-right corner.
If a list of compilers appeared, we chose the first option.
Following these steps resolved the issue for us in 90% of cases. However, if the problem persists, another option is to try an online C++ compiler with a debug option.
Deleting the .vscode folder and reattempting the debugging process is a quick and simple workaround that often resolves configuration-related issues. Additionally, using an online C++ compiler with a debug option can be a viable alternative if debugging locally continues to pose challenges.
We encountered an error where the preLaunchTask terminated with exit code -1, and the launch program was reported as not existing.
To resolve this issue, we followed these steps:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "gcc",
"args": ["-o", "program.exe", "main.c"],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"launch": {
"version": "0.2.0",
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/program.exe",
"cwd": "${workspaceFolder}",
"externalConsole": false
}
]
}
}
In our case, we encountered the error message "the preLaunchTask build terminated with exit code -1, launch program does not exist" while working with a C/C++ project in Visual Studio Code.
To address this issue, we made modifications to the tasks.json file:
{
"label": "g++.exe build active file",
"args": [
"-g",
"${fileDirname}\\**.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
By adding this task configuration, we ensured that the build process includes debugging symbols ("-g") and compiles all .cpp files in the directory. The output executable is saved with the same name as the source file but with the .exe extension.
After updating the tasks.json file, we ran the build task by either debugging or running the C/C++ file directly (not just clicking "Run Code").
Following these steps allowed us to resolve the issue, and the project built successfully without encountering the preLaunchTask termination error.
We resolved the issue by making a modification to the tasks.json file.
Instead of using "${file}" as the argument for the build task, we replaced it with "${workspaceFolder}\*.cpp".
Here's how the updated task configuration looks:
{
"label": "g++.exe build active file",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
By using "${workspaceFolder}\*.cpp", we instructed the build task to compile all .cpp files within the workspace folder.
Implementing this change allowed us to successfully compile all .cpp files in the workspace, resolving the issue.
To ensure that all source files within the workspace are compiled during the build process. Using "${file}" may not capture all source files if they are located in different directories within the workspace. By specifying "${workspaceFolder}\*.cpp", we ensure that all relevant source files are included in the build.