【问题标题】:Debug C++ DLL with VSCode instead of Visual Studio使用 VSCode 而不是 Visual Studio 调试 C++ DLL
【发布时间】:2021-11-21 10:25:46
【问题描述】:

我正在开发一个需要调试 C++ DLL/Lib 的项目。我有 DLL/PDB/H/Source 文件,我需要一个“客户端”来调用 DLL,这样我就可以调试一些功能。

到目前为止,我在 Visual Studio 中有一个“DLL 客户端”的解决方案。为了让它工作,我必须添加我的“附加包含目录”(.h 文件),“链接器”上的 dll 路径,并在“构建事件”中对 dll/pdb 进行 xcopy。 这是可行的,但我不太喜欢 Visual Studio 界面,想尝试使用 VSCode 进行编码/调试。

到目前为止,我的客户非常简单:

    #include <iostream>
    #include "mydll.h"
    
    int main()
    {
        char version[20];
        GetVersion(version);
        std::cout << "Version: " << version << '\n';
    }

我的 DLL 是用 makefile 制作的。我在如何在 VSCode 上设置我的 launch.json(或设置什么)以添加包含目录和 pdb 信息时遇到问题,所以当我运行我的客户端时,dll/pdb 链接到客户端。

launch.json 是 vscode 的默认值,只是改了个名字

{"configurations": [
    {
        "name": "(gdb) DLL Client",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/dllclient.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
            {
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
    ]
}

有什么帮助吗?谢谢

【问题讨论】:

标签: c++ visual-studio debugging visual-studio-code dll


【解决方案1】:

所以,我不知道它是否是最好的解决方案,但它是我能找到的。可能有一些方法可以通过 vscode 的 C++ 扩展来改善这一点。

launch.json(用于调试)

{"configurations": [
    {
        "name": "(gdb) VCVarsall 32",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "${workspaceFolder}\\main.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "targetArchitecture": "x86",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "preLaunchTask": "C++: vcvarsall Main 32",
    },
]}

tasks.json(构建主库和链接库)

{
    "tasks": [
        {
            "type": "process",
            "label": "C++: vcvarsall Main 32",
            "command": "cmd",
            "options": {"cwd": "${workspaceFolder}"},
            "args": ["/C vcvarsall x86 && cl /Od /Zi /EHsc /Fd:vc140.pdb /Fo:main.obj ./main.cpp /I ${workspaceFolder}\\dev /link ${workspaceFolder}\\libs\\mylibrary.lib /OUT:main.exe /PDB:vc140.pdb"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ],
    "version": "2.0.0"
}

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2014-01-05
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-04
    • 2018-12-21
    • 1970-01-01
    相关资源
    最近更新 更多