本文介绍了如何使用漂亮的调试打印机看到Eigen对象在QtCreator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在 QtCreator 的地方和表达式窗口中查看特征向量的内容: > 我看到它是一个有10个组件的向量: 但是当我点击它打开我会得到: 我试图使用这个脚本做的招。我将它与一个空的 _ init _。py 文件保存到文件夹〜/ Scripts / Eigen ,并创建了 .gdbinit 文件: python import sys sys.path.insert(0,'/ home / martin / Scripts / Eigen')来自打印机import register_eigen_printers register_eigen_printers(无) end 我重新启动 QtCreator ,没有任何变化。我在QtCreator设置中检查了启动时读取.gdbinit 选项。 令我担心的是我知道在过去观看Eigen对象的工作没有我插手一些脚本。 请问我做错了什么? 我使用的是: gcc version 4.8.1 Ubuntu 13.10 gdb 7.6.1-ubuntu Qt Creator 3.0.0 基于Qt 5.2.0 ,我正在使用以下标志进行编译: g ++ -c -pipe -gdwarf-4 -fvar-tracking-assignments -g -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG 编辑: as @ggael建议,我试图直接运行 gdb : b $ b启动程序:/ home / martin / Projects / TestGrounds / test 回溯(最近调用最后一次):文件/ usr / lib / debug / usr / lib / i386-linux-gnu /libstdc++.so.6.0.18-gdb.py,第59行,在< module> from libstdcxx.v6.printers import register_libstdcxx_printers ImportError:没有名为'libstdcxx'的模块回溯(最近一次调用):文件/ usr / lib / debug / usr /lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py,第59行,< module> from libstdcxx.v6.printers import register_libstdcxx_printers ImportError:没有名为'libstdcxx'的模块 然后: (gdb)print vec Python异常< class'TypeError' 'map'object is not subscriptable: Python Exception< class'TypeError'> 'map'对象不是可下标的: $ 1 = {< Eigen :: PlainObjectBase< Eigen :: Matrix< double,-1,1,0,-1,1& >> = {< Eigen :: MatrixBase< Eigen :: Matrix< double,-1,1,0,-1,1> >> = {< Eigen :: DenseBase< Eigen :: Matrix< double,-1,1,0,-1,1> >> = {< Eigen :: internal :: special_scalar_op_base< Eigen :: Matrix< double,-1,1,0,-1,1>,double,double,false> = {< Eigen :: DenseCoeffsBase< Eigen :: Matrix< double,-1,1,0,-1,1> ;, 3> = {< Eigen :: DenseCoeffsBase< Eigen :: Matrix< double,-1,1,0,-1,1>,1> = {< Eigen :: DenseCoeffsBase< Eigen :: Matrix< double,-1,1,0,-1,1>,0> = {< Eigen :: EigenBase< Eigen :: Matrix< double,-1,1,0,-1,1> >> = {< No data fields>},< No data fields>},< No data fields>},< No data fields>},< No data fields>},< No data fields& < No data fields>}, m_storage = {m_data = 0x804e020,m_rows = 10}},< No data fields>} 请你能解释一下这是什么意思吗?什么是 libstdcxx ?解决方案问题可能在调试器本身。我尝试了许多组合 加载\不加载 .gdbinit 加载\不加载系统漂亮的打印机 使用\不使用代码模型 -gdwarf-x编译器标志 ,这些都不重要。然后,我尝试使用旧的 GDB 7.4 和全新的 QtCreator 3.0.1 全新安装 Ubuntu 12.04 我对 gcc 4.6 , gcc 4.7 和 gcc 4.8.1 获得了相同的结果。 然后,我在 Ubuntu 13.10 上尝试了最新的 GDB 7.7 ,再次运行,而 GDB 7.5,GDB 7.6 不工作。 还有一个奇怪的事情, std :: shared_ptr 正确查看 >在 QtCreator 3.0.1 中。 std :: multimap #include< iostream> #include< vector> #include< map> #include< string> #include< memory> #include< eigen3 / Eigen / Dense> int main(int argc,char * argv []) { std :: vector< int> vec(4,3); std :: map< int,std :: string> map = {{1,one},{2,two},{3,three}}; std :: multimap< int,std :: string> multi = {{1,one},{2,two},{3,three}}; Eigen :: VectorXd vector = Eigen :: VectorXd :: Constant(3,3.14); std :: shared_ptr< Eigen :: VectorXd>指针(new Eigen :: VectorXd(vector)); std :: cout<<载体< std :: endl; return 0; } I am trying to see the contents of an Eigen vector in the Locals and Expressions window of the QtCreator:I see that it is a vector with 10 components:but when I click it open I get:I tried to use this script to do the trick. I saved it along with an empty _init_.py file into folder ~/Scripts/Eigen and created the .gdbinit file:pythonimport syssys.path.insert(0, '/home/martin/Scripts/Eigen')from printers import register_eigen_printersregister_eigen_printers (None)endI restarted QtCreator and nothing changed. I have checked the "read .gdbinit at startup" option in QtCreator settings and still nothing.What is worrying me is that I know that in the past the viewing of Eigen objects worked without me meddling with some scripts.Please, what am I doing wrong?I am using:gcc version 4.8.1Ubuntu 13.10gdb 7.6.1-ubuntuQt Creator 3.0.0Based on Qt 5.2.0and I am compiling using these flags:g++ -c -pipe -gdwarf-4 -fvar-tracking-assignments -g -Wall -W -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUGEDIT:as @ggael suggested, I tried to run the gdb directly:(gdb) runStarting program: /home/martin/Projects/TestGrounds/testTraceback (most recent call last): File "/usr/lib/debug/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py", line 59, in <module> from libstdcxx.v6.printers import register_libstdcxx_printersImportError: No module named 'libstdcxx'Traceback (most recent call last): File "/usr/lib/debug/usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py", line 59, in <module> from libstdcxx.v6.printers import register_libstdcxx_printersImportError: No module named 'libstdcxx'And then:(gdb) print vecPython Exception <class 'TypeError'> 'map' object is not subscriptable:Python Exception <class 'TypeError'> 'map' object is not subscriptable:$1 = {<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::DenseBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<Eigen::internal::special_scalar_op_base<Eigen::Matrix<double, -1, 1, 0, -1, 1>, double, double, false>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 3>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 1>> = {<Eigen::DenseCoeffsBase<Eigen::Matrix<double, -1, 1, 0, -1, 1>, 0>> = {<Eigen::EigenBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >> = {<No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, <No data fields>}, m_storage = {m_data = 0x804e020, m_rows = 10}}, <No data fields>}Please, could you explain what does this mean? What is libstdcxx? 解决方案 The problem was probably in the debugger itself. I tried out many combinations ofload \ do not load .gdbinitload \ do not load system pretty printersuse \ don't use code model-gdwarf-x compiler flagsand none of this really mattered. Then I tried a fresh install of Ubuntu 12.04 with old GDB 7.4 and a brand new QtCreator 3.0.1 and it worked! I got the same results forgcc 4.6, gcc 4.7 and gcc 4.8.1.Then I tried the newest GDB 7.7 on Ubuntu 13.10 and again it worked, while GDB 7.5, GDB 7.6 did not work.Also a strange thing, std::shared_ptr is correctly viewed only in QtCreator 3.0.1.std::multimap is not pretty printed in any configuration.#include <iostream>#include <vector>#include <map>#include <string>#include <memory>#include <eigen3/Eigen/Dense>int main(int argc, char *argv[]){ std::vector<int> vec(4, 3); std::map<int, std::string> map = {{1,"one"},{2,"two"},{3,"three"}}; std::multimap<int, std::string> multi = {{1,"one"},{2,"two"},{3,"three"}}; Eigen::VectorXd vector = Eigen::VectorXd::Constant(3, 3.14); std::shared_ptr<Eigen::VectorXd> pointer(new Eigen::VectorXd(vector)); std::cout << vector << std::endl; return 0;} 这篇关于如何使用漂亮的调试打印机看到Eigen对象在QtCreator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-27 16:55