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:

  1. Open your Visual Studio Code workspace.
  2. Go to the "Tasks" menu and select "Configure Tasks".
  3. Find the prelaunch task named "c/c++: clang build active file".
  4. Review the configuration of this task to ensure it is correctly set up.
  5. Check if there are any errors in the task configuration, such as missing or incorrect paths, commands, or arguments.
  6. If necessary, make corrections to the task configuration to resolve any issues.
  7. Save the changes to the task configuration file.
  8. Reload Visual Studio Code or restart the IDE to apply the changes.
  9. Attempt to run the prelaunch task again to see if the error persists.
  10. If the error persists, review any error messages or logs provided to identify the specific cause of the issue.

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.

Solution-2

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:

  1. Ensure that the necessary build tools, such as g++, are installed and accessible in your system's PATH environment variable.

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"
    }
  ]
}


Solution 3

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.

Solution 4

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:

  1. We checked the configuration of the preLaunchTask to ensure it was correctly set up.
  2. We verified that the build task specified in the preLaunchTask configuration existed and was properly configured to build the program.
  3. We also checked if the launch program specified in the launch configuration existed in the specified location.
  4. If the path to the launch program was incorrect or if the program itself was missing or not built properly, we corrected the configuration.
  5. After ensuring the correctness of the configuration, we attempted to rerun the preLaunchTask and launch the program again.
  6. If the error persisted despite verifying the configuration, we investigated other potential factors such as environmental issues, conflicting dependencies, or system settings.


{
  "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
      }
    ]
  }
}


Solution 6

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.


Solution 7

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.