【问题标题】:setup Vscode for debbuging Eigen设置 Vscode 用于调试 Eigen
【发布时间】:2021-05-29 11:18:01
【问题描述】:

我正在使用 Eigen 库 (https://eigen.tuxfamily.org/dox/GettingStarted.html) 进行一些计算。

我正在运行的程序是:

#include <iostream>
#include <Eigen/Dense>
 
using Eigen::MatrixXd;
 
int main()
{
  MatrixXd m(2,2);
  m(0,0) = 3;
  m(1,0) = 2.5;
  m(0,1) = -1;
  m(1,1) = m(1,0) + m(0,1);
  std::cout << m << std::endl;
}

在他们的文档中推荐编译:

g++ -I /path/to/eigen/ my_program.cpp -o my_program 

如果我运行它,它会编译并运行...但现在我希望能够通过代码进行调试。

我正在使用生成的.json 文件是:

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-I",
                "${eigen}",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/pc/eigen/" 
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

此配置仅运行代码,但不会将调试器粘在上面。

非常感谢您的帮助!

【问题讨论】:

    标签: visual-studio-code vscode-debugger eigen3


    【解决方案1】:

    好的,这对我有用:

    1º 下载特征:

    https://eigen.tuxfamily.org/index.php?title=Main_Page
    

    2º 创建一个指向 eigen 文件夹的符号链接

    sudo ln -s location/of/Eigen/Folder  /usr/local/include/
    

    3º 可以编译代码:

    g++ my_program.cpp -o my_program 
    

    4º 要“更好地调试” Eigen,请为 gdb 使用自定义 python 打印机

    https://gitlab.com/libeigen/eigen/-/blob/master/debug/gdb/printers.py
    
    a) Create a hidden file called gdbinit 
        touch ~/.gdbinit
    b) Place the following code in it:
        python
        import sys
        sys.path.insert(0, '/path/to/eigen/printer/directory')  #In my case it was /home/pc/eigen/debug/gdb
        from printers import register_eigen_printers
        register_eigen_printers (None)
        end
    

    注意:VScode 开箱即用(F5 和调试模式已打开!)

    【讨论】:

      猜你喜欢
      • 2023-01-29
      • 2019-07-19
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      相关资源
      最近更新 更多