未加载符号:libmex.pdb 未加载(throw_segv_longjmp_seh_filter() = EXCEPTION_CONTINUE_SEARCH:C++ 异常)
No Symbols Loaded: libmex.pdb not loaded (throw_segv_longjmp_seh_filter() = EXCEPTION_CONTINUE_SEARCH : C++ exception)
为了创建一个 MEX function
并在我的 MATLAB
代码中使用它,像这样:
[pow,index] = mx_minimum_power(A11,A12,A13,A22,A23,A33);
我创建了文件 mx_minimum_power.cpp
并在其中编写了以下代码:
#include <math.h>
#include <complex>
#include "mex.h"
#include "matrix.h"
#include "cvm.h"
#include "blas.h"
#include "cfun.h"
using std::complex;
using namespace cvm;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
const int arraysize = 62172;
const int matrixDimention = 3;
float *inMatrixA11 = (float *)mxGetPr(prhs[0]);
complex<float> *inMatrixA12 = (complex<float> *)mxGetPr(prhs[1]);
complex<float> *inMatrixA13 = (complex<float> *)mxGetPr(prhs[2]);
float *inMatrixA22 = (float *)mxGetPr(prhs[3]);
complex<float> *inMatrixA23 = (complex<float> *)mxGetPr(prhs[4]);
float *inMatrixA33 = (float *)mxGetPr(prhs[5]);
basic_schmatrix< float, complex<float> > A(matrixDimention);
int i = 0;
for (i = 0; i < arraysize; i++)
{
A.set(1, 1, inMatrixA11[i]);
A.set(1, 2, inMatrixA12[i]);
A.set(1, 3, inMatrixA13[i]);
A.set(2, 2, inMatrixA22[i]);
A.set(2, 3, inMatrixA23[i]);
A.set(3, 3, inMatrixA33[i]);
}
}
然后为了能够调试代码,我创建了 mx_minimum_power.pdb
和 mx_minimum_power.mexw64
文件,在 Matlab Command Window
中使用以下代码:
mex -g mx_minimum_power.cpp cvm_em64t_debug.lib
文件 blas.h
、cfun.h
、cvm.h
和 cvm_em64t_debug.lib
与 mx_minimum_power.cpp
在同一目录中。
它们是CVM Class Library.
的头文件和库文件
然后我使用 explained here.
的方式将 MATLAB.exe
附加到 Visual Studio 2013
并在 line40
处设置了 breakpoint
:
当我运行我的MATLAB
代码时,直到指定的行都没有错误。
但是如果我点击 Step Over
按钮,我会遇到以下消息:
将以下信息添加到 Output
:
First-chance exception at 0x000007FEFCAE9E5D in MATLAB.exe: Microsoft C++ exception: cvm::cvmexception at memory location 0x0000000004022570.
> throw_segv_longjmp_seh_filter()
throw_segv_longjmp_seh_filter(): C++ exception
< throw_segv_longjmp_seh_filter() = EXCEPTION_CONTINUE_SEARCH
你能告诉我为什么在该行需要 libmex.pdb
吗?我应该如何解决这个问题?
如果我停止调试,我将在 MATLAB Command Window
中获得以下信息:
Unexpected Standard exception from MEX file.
What() is:First index value 0 is out of [1,4) range
就在按下 step over
按钮之前,我们有以下 A11[0],A12[0],A13[0],A22[0],A23[0],A33[0]
的值:
根据 MATLAB
传递给 MEX
函数的内容,这正好符合我的预期:
可能是矩阵A
分配错误导致的问题,按下step over
按钮前如下。
出现这个问题是因为我们在cvm.h
文件的第48到53行有如下代码:
// 5.7 0-based indexing
#if defined (CVM_ZERO_BASED)
# define CVM0 TINT_ZERO //!< Index base, 1 by default or 0 when \c CVM_ZERO_BASED is defined
#else
# define CVM0 TINT_ONE //!< Index base, 1 by default or 0 when \c CVM_ZERO_BASED is defined
#endif
默认情况下 CVM0 = 1
。因此,如果我们在指定行按两次 Step Into(F11)
按钮,我们将进入文件 cvm.h
的第 34883 行:
basic_schmatrix& set(tint nRow, tint nCol, TC c) throw(cvmexception)
{
this->_set_at(nRow - CVM0, nCol - CVM0, c);
return *this;
}
在第 this->_set_at(nRow - CVM0, nCol - CVM0, c);
行按 Step Into(F11)
,您将转到函数 _set_at
的定义:
// sets both elements to keep matrix hermitian, checks ranges
// zero based
void _set_at(tint nRow, tint nCol, TC val) throw(cvmexception)
{
_check_lt_ge(CVM_OUTOFRANGE_LTGE1, nRow, CVM0, this->msize() + CVM0);
_check_lt_ge(CVM_OUTOFRANGE_LTGE2, nCol, CVM0, this->nsize() + CVM0);
if (nRow == nCol && _abs(val.imag()) > basic_cvmMachMin<TR>()) { // only reals on main diagonal
throw cvmexception(CVM_BREAKS_HERMITIANITY, "real number");
}
this->get()[this->ld() * nCol + nRow] = val;
if (nRow != nCol) {
this->get()[this->ld() * nRow + nCol] = _conjugate(val);
}
}
按Step Over(F10)
按钮,你会得到结果:
所以为了得到 nRow=1
和 nCol=1
而不是 nRow=0
和 nCol=0
,它超出了范围 [1,4)
,你应该写该行代码为:
A.set(2, 2, inMatrixA11[i]);
为了创建一个 MEX function
并在我的 MATLAB
代码中使用它,像这样:
[pow,index] = mx_minimum_power(A11,A12,A13,A22,A23,A33);
我创建了文件 mx_minimum_power.cpp
并在其中编写了以下代码:
#include <math.h>
#include <complex>
#include "mex.h"
#include "matrix.h"
#include "cvm.h"
#include "blas.h"
#include "cfun.h"
using std::complex;
using namespace cvm;
/* The gateway function */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
const int arraysize = 62172;
const int matrixDimention = 3;
float *inMatrixA11 = (float *)mxGetPr(prhs[0]);
complex<float> *inMatrixA12 = (complex<float> *)mxGetPr(prhs[1]);
complex<float> *inMatrixA13 = (complex<float> *)mxGetPr(prhs[2]);
float *inMatrixA22 = (float *)mxGetPr(prhs[3]);
complex<float> *inMatrixA23 = (complex<float> *)mxGetPr(prhs[4]);
float *inMatrixA33 = (float *)mxGetPr(prhs[5]);
basic_schmatrix< float, complex<float> > A(matrixDimention);
int i = 0;
for (i = 0; i < arraysize; i++)
{
A.set(1, 1, inMatrixA11[i]);
A.set(1, 2, inMatrixA12[i]);
A.set(1, 3, inMatrixA13[i]);
A.set(2, 2, inMatrixA22[i]);
A.set(2, 3, inMatrixA23[i]);
A.set(3, 3, inMatrixA33[i]);
}
}
然后为了能够调试代码,我创建了 mx_minimum_power.pdb
和 mx_minimum_power.mexw64
文件,在 Matlab Command Window
中使用以下代码:
mex -g mx_minimum_power.cpp cvm_em64t_debug.lib
文件 blas.h
、cfun.h
、cvm.h
和 cvm_em64t_debug.lib
与 mx_minimum_power.cpp
在同一目录中。
它们是CVM Class Library.
然后我使用 explained here.
的方式将 MATLAB.exe
附加到 Visual Studio 2013
并在 line40
处设置了 breakpoint
:
当我运行我的MATLAB
代码时,直到指定的行都没有错误。
但是如果我点击 Step Over
按钮,我会遇到以下消息:
将以下信息添加到 Output
:
First-chance exception at 0x000007FEFCAE9E5D in MATLAB.exe: Microsoft C++ exception: cvm::cvmexception at memory location 0x0000000004022570.
> throw_segv_longjmp_seh_filter()
throw_segv_longjmp_seh_filter(): C++ exception
< throw_segv_longjmp_seh_filter() = EXCEPTION_CONTINUE_SEARCH
你能告诉我为什么在该行需要 libmex.pdb
吗?我应该如何解决这个问题?
如果我停止调试,我将在 MATLAB Command Window
中获得以下信息:
Unexpected Standard exception from MEX file.
What() is:First index value 0 is out of [1,4) range
就在按下 step over
按钮之前,我们有以下 A11[0],A12[0],A13[0],A22[0],A23[0],A33[0]
的值:
根据 MATLAB
传递给 MEX
函数的内容,这正好符合我的预期:
可能是矩阵A
分配错误导致的问题,按下step over
按钮前如下。
出现这个问题是因为我们在cvm.h
文件的第48到53行有如下代码:
// 5.7 0-based indexing
#if defined (CVM_ZERO_BASED)
# define CVM0 TINT_ZERO //!< Index base, 1 by default or 0 when \c CVM_ZERO_BASED is defined
#else
# define CVM0 TINT_ONE //!< Index base, 1 by default or 0 when \c CVM_ZERO_BASED is defined
#endif
默认情况下 CVM0 = 1
。因此,如果我们在指定行按两次 Step Into(F11)
按钮,我们将进入文件 cvm.h
的第 34883 行:
basic_schmatrix& set(tint nRow, tint nCol, TC c) throw(cvmexception)
{
this->_set_at(nRow - CVM0, nCol - CVM0, c);
return *this;
}
在第 this->_set_at(nRow - CVM0, nCol - CVM0, c);
行按 Step Into(F11)
,您将转到函数 _set_at
的定义:
// sets both elements to keep matrix hermitian, checks ranges
// zero based
void _set_at(tint nRow, tint nCol, TC val) throw(cvmexception)
{
_check_lt_ge(CVM_OUTOFRANGE_LTGE1, nRow, CVM0, this->msize() + CVM0);
_check_lt_ge(CVM_OUTOFRANGE_LTGE2, nCol, CVM0, this->nsize() + CVM0);
if (nRow == nCol && _abs(val.imag()) > basic_cvmMachMin<TR>()) { // only reals on main diagonal
throw cvmexception(CVM_BREAKS_HERMITIANITY, "real number");
}
this->get()[this->ld() * nCol + nRow] = val;
if (nRow != nCol) {
this->get()[this->ld() * nRow + nCol] = _conjugate(val);
}
}
按Step Over(F10)
按钮,你会得到结果:
所以为了得到 nRow=1
和 nCol=1
而不是 nRow=0
和 nCol=0
,它超出了范围 [1,4)
,你应该写该行代码为:
A.set(2, 2, inMatrixA11[i]);