我收到“cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 TestProject.exe.stackdump”错误。我的项目只不过是一个 C++ HalloWorld 项目,它包含一个附加类,我在其中设置和获取一个变量。我在尝试设置 Eigen 类型的矩阵变量的那一行遇到了这个错误。这是我的代码:
测试项目.cpp
#include <iostream>
#include "TestClass.hpp"
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
TestClass testClass;
Eigen::MatrixXd XX = testClass.getVariable();
cout << "X = " << XX;
return 0;
}
测试类.hpp:
#ifndef TESTCLASS_HPP_
#define TESTCLASS_HPP_
#include <Eigen/Core>
#include <Eigen/Eigenvalues>
#include <unsupported/Eigen/MatrixFunctions>
#include <Eigen/Geometry>
class TestClass {
private:
Eigen::MatrixXd X;
public:
TestClass();
void setVariable(Eigen::MatrixXd);
Eigen::MatrixXd getVariable();
virtual ~TestClass();
};
#endif /* TESTCLASS_HPP_ */
最后是 TestClass.cpp:
#include "TestClass.hpp"
using namespace std;
TestClass::TestClass() {
X << 0, 1, 2;
}
TestClass::~TestClass() {
// TODO Auto-generated destructor stub
}
void TestClass::setVariable(Eigen::MatrixXd x){
X = x;
}
/* namespace std */
Eigen::MatrixXd TestClass::getVariable(){
return X;
}
我在控制台中得到的输出是:
!!!Hello World!!!
0 [main] TestProject 8416 cygwin_exception::open_stackdumpfile: Dumping stack trace to TestProject.exe.stackdump
值得一提的是,当我将类变量 X 的类型(以及方法和头文件中的所有相关类型)更改为整数时,我没有收到此错误并且代码编译并运行。
我将不胜感激,因为我没有在网上找到有用的信息。
谢谢
最佳答案
您正在使用一个动态大小的 Matrix X,并且您尝试在不先设置其大小的情况下对其进行逗号初始化。这将引发异常:
如解释here :
Eigen offers a comma initializer syntax which allows the user to easily set all the coefficients of a matrix, vector or array. Simply list the coefficients, starting at the top-left corner and moving from left to right and from the top to the bottom. The size of the object needs to be specified beforehand.
和here :
The coefficients must be provided in a row major order and exactly match the size of the matrix. Otherwise an assertion is raised.
所以首先调整矩阵的大小:
TestClass::TestClass() {
X.resize (1,3);
X << 0, 1, 2;
}
关于c++ - cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 *.exe.stackdump,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31676122/