【问题标题】:Debugging with gdb and armadillo使用 gdb 和犰狳进行调试
【发布时间】:2021-03-17 07:03:13
【问题描述】:

使用armadillo C++ 库时,我需要使用g++ 标志-larmadillo 进行编译以链接运行时犰狳库。如果没有,我会收到许多未定义的引用错误。

但是,当我想使用gdb 进行调试时,我仍然会得到这些未定义的引用。如何让gdb 使用链接库而不会出错?或者,我怎样才能以gdb(或任何其他调试器)可以工作的方式进行编译?

我正在使用 VS 代码。我的:tasks.jsonlaunch.json

【问题讨论】:

    标签: c++ visual-studio-code gdb armadillo


    【解决方案1】:

    对我来说,当我在 tasks.json 文件中将类型更改为 "type": "shell", 时,它起作用了。这是我在 Armadillo 文档中用于基本示例的设置。

    tasks.json

    {
        "version": "2.0.0",
        "tasks": [
            {
                "type": "shell",
                "label": "C/C++: g++ build active file",
                "command": "/usr/bin/g++",
                "args": [
                    "-ggdb",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}",
                    "-std=c++11",
                    "-O2",
                    "-larmadillo"
                ],
                "options": {
                    "cwd": "${workspaceFolder}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "compiler: /usr/bin/g++"
            }
        ]
    }
    

    launch.json

    {
        "configurations": [
          {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "${defaultBuildTask}",
          }
        ]
      }
    

    【讨论】:

    • 嗯,解决了它。我之前将 "type": "shell" 更改为 "type": "cppbuild" 试图修复其他问题,但现在一切正常。
    猜你喜欢
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 2015-07-01
    • 2011-05-01
    相关资源
    最近更新 更多