设置Vscode以解除对Eigen的编译



我正在使用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"
}

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

这个配置只是运行代码,但不会让调试器坚持下去

非常感谢您的帮助!

好的,所以这对我有效:

1º下载特征:

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

2º创建到特征文件夹的符号链接

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和调试模式开启!(

相关内容

  • 没有找到相关文章

最新更新