c++ - 无法在 VS Code 中多次使用预启动任务

标签 c++ json visual-studio-code mingw-w64 bgi

我尝试多次使用预启动任务来执行我的 launch.json 文件中的两个不同任务。不幸的是,它只执行我的 launch.json 文件中的最后一个预启动任务。我的 tasks.json 中的任务使用相同的命令(“g++”)来编译我的程序,但它们的参数不同(那是因为我需要先将我的源代码编译成一个“O”文件然后编译“O” "文件转换为 "exe"文件),所以我正在寻找一种方法,了解如何仅使用一个预启动任务在 launch.json 文件中执行这两个任务。还有其他想法吗?

任务.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
        }
    ]
}

启动.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
                }
            ]
        }
    ]
}

最佳答案

您只能有一个preLaunchTask,但您可以将"dependsOn": "CompileToOfile" 添加到您的CompileWGDBWBGI 任务,然后使用它作为您的 preLaunchTask。这样,CompileToOfile 在每次执行 CompileWGDBWBGI 之前执行。

关于c++ - 无法在 VS Code 中多次使用预启动任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051616/

相关文章:

c++ - (修订)prefix++和postfix++有什么区别?

c++ - 函数值参数的常量性特征?

javascript - Javascript 中形成的 URL 无效

visual-studio-code - 字符 "["(altgr+F) 没有出现在客户端?

python - 如何修复 vscode 中的 'jupyter notebook server failed to launch in time'?

c++ - 零MQ/ZMQPP : Forward metadata with message

c++ - 传统上如何在 C++ 中实现多类型容器(数组/vector/列表)? (当然没有元组)

java - JsonObject 和 JSONObject 有什么不同

json - 为什么 Kotlin Object 类到 json 对象为 null?

visual-studio-code - 保存vscode扩展的用户首选项/设置