I'm trying to use pre-launch task more than once to execute two different tasks in my launch.json file. Unfortunately, it only executes the last pre-launch task in my launch.json file. The tasks that are in my tasks.json use the same command("g++") to compile my program, but their arguments are different (that's because I need to compile my source code first into an "O" file then compile the "O" file into an "exe" file), so I'm finding a way on how can I execute those two tasks in the launch.json file using one pre-launch task only. Any other ideas please?
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"tasks": [
{
"taskName": "CompileToOfile",
"command": "g++",
"args": [
"-c","${fileBasename}",
"-o","${fileBasenameNoExtension}.o",
"-I","/Users/Acer/MinGW64/include",
"-I","/Users/Acer/MinGW64/x86_64-w64-mingw32/include",
"-I","/Users/Acer/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include",
"-I","/Users/Acer/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++",
"-m32"
],
"isShellCommand": true
},
{
"taskName": "CompileWGDBWBGI",
"command": "g++",
"args": [
"${fileBasenameNoExtension}.o",
"-o",
"${fileBasenameNoExtension}.exe",
"-L","/Users/Acer/MinGW64/lib32",
"-L","Users/Acer/MinGW64/x86_64-w64-mingw32/lib32",
"-static-libgcc",
"-lbgi",
"-lgdi32",
"-lcomdlg32",
"-luuid",
"-loleaut32",
"-lole32",
"-m32"
],
"isShellCommand": true
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"preLaunchTask": "CompileToOfile",
"preLaunchTask": "CompileWGDBWBGI",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "CompileToOfile",
"preLaunchTask": "CompileWGDBWBGI",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/Users/Acer/MinGW64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
You can only have one preLaunchTask
, but you could add "dependsOn": "CompileToOfile"
to your CompileWGDBWBGI
task and then use that as your preLaunchTask
. This way, CompileToOfile
is executed before each execution of CompileWGDBWBGI
.