Solved Error: "The preLaunchTask 'C/C++: g++.exe build active file' terminated with exit code 1"


In our case, we encountered an issue related to the auto-generated .vscode folder when debugging for the first time. To resolve this problem, we followed these steps:

  1. We deleted the .vscode folder.
  2. Then, we debugged again by pressing F5 or selecting "Debug" from the top right and choosing the appropriate option if any list for the compiler appeared.
  3. If we had previously compiled our code and the executable (*.exe) file was already created, we deleted it through the VS Code file explorer.
  4. We tried to build our code again. The issue, in our case, was that VS Code could not delete the executable to create a new one.
  5. In another case, it was a problem with the location of the gcc.exe file in the command location of the tasks.json file. We made the necessary changes to this location, and it worked fine afterwards.

The deletion of the executable file, and the location of the gcc.exe file. By following these steps, we were able to resolve the debugging issues in VS Code and successfully build our code.

2

If you are encountering the error message "the prelaunchtask 'c/c++: clang build active file' terminated with exit code -1" in your C/C++ development environment, it is likely related to issues with the prelaunch task configuration or the build settings. Here's a detailed solution to solve this problem:

  1. Check Build Configuration: Ensure that your build configurations are set up correctly. Verify that you have the necessary build tools installed, and the compiler paths are correctly configured.
  2. Task Configuration: Examine the prelaunch task configuration in your development environment. This could be defined in a configuration file, such as tasks.json in Visual Studio Code. Make sure the task is correctly defined, and there are no errors or typos in the configuration.
  3. Compiler Installation: Confirm that your Clang compiler is installed properly. Ensure that the compiler executable is in the system's PATH or adjust the PATH variable to include the directory where the compiler is located.
  4. File-specific Issues: If the error is occurring with a specific file, check the file for syntax errors, missing dependencies, or any other issues that might cause the build to fail.
  5. Update Extensions: If you are using an IDE or code editor with extensions related to C/C++ development, make sure they are up to date. Outdated or incompatible extensions can sometimes cause build errors.

Here's an example of a possible tasks.json configuration for building a C++ file with Clang:

  
  {
    "version": "2.0.0",
    "tasks": [
      {
        "label": "clang-build-active-file",
        "type": "shell",
        "command": "clang++",
        "args": [
          "-std=c++11",
          "-o",
          "${fileBasenameNoExtension}.out",
          "${file}"
        ],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
  }
  
  

After applying these steps, try building your C/C++ project again. If the issue still persists, carefully review any error messages in the console or build output for additional information about the root cause of the problem.

3

To fix this issue, I made the following configuration changes in my launch.json file:


"-arch", "x86_64",

"targetarchitecture": "x86_64",
"osx": {
    "prelaunchtask": "c/c++: g++ build active file",
    "mimode": "lldb"
}
    

These changes specify the architecture as x86_64 and set the appropriate prelaunch task and debugging mode for macOS, resolving the issue.

4

I encountered the same problem, and I found that Visual Studio Code (VSCode) does not currently support a debugger for arm64 binaries.

However, I discovered a workaround by using another extension. You can install codelldb and set "type": "lldb" in your launch.json file as shown below:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++ - build and debug active file",
            "type": "lldb",
            "request": "launch",
            "program": "${filedirname}/${filebasenamenoextension}",
            "args": [],
            "cwd": "${workspacefolder}",
            "prelaunchtask": "clang++ build active file"
        }
    ]
}

This configuration allows you to use the codelldb extension for debugging, resolving the issue with debugging arm64 binaries in VSCode.

5

If none of the above solutions work, we can try the following steps:

  1. Delete the contents in the .vscode folder.
  2. Close the remote connection.
  3. Close and reopen VSCode.
  4. Alternatively, we can try replacing "${file}" with "${workspaceFolder}\*.cpp" in the tasks.json file.

Deleting the contents in the .vscode folder and restarting VSCode can help reset any potential configuration issues. Additionally, replacing "${file}" with "${workspaceFolder}\*.cpp" in the tasks.json file ensures that the correct files are targeted for compilation. By following these steps, we can resolve the issues with executing C/C++ programs in VSCode.