没有加载符号:未​​加载libmex.pdb(throw_segv_longjmp_seh_filter()= EXCEPTION_CONTINUE_SEARCH:C ++异常)

时间:2016-09-09 17:23:17

标签: matlab exception visual-c++ mex pdb-files

要创建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.mexw64Matlab Command Window个文件:

mex -g mx_minimum_power.cpp cvm_em64t_debug.lib  

文件blas.hcfun.hcvm.hcvm_em64t_debug.libmx_minimum_power.cpp位于同一目录中。
它们是CVM Class Library的标题和库文件。

然后我使用explained here的方式将MATLAB.exe附加到Visual Studio 2013
并在breakpoint设置了line40

enter image description here

当我运行MATLAB代码时,在指定的行之前没有错误。

enter image description here

但如果我点击Step Over按钮,我会遇到以下消息:

enter image description here

将以下信息添加到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  

enter image description here

您能否建议我为什么需要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]提供了以下值:

enter image description here

根据{{​​1}}传递给MATLAB函数的内容,

符合我的预期:
enter image description here

可能问题是由于矩阵MEX的分配错误,在按下A按钮之前如下所示。

enter image description here

1 个答案:

答案 0 :(得分:0)

出现问题是因为我们在int loops文件的第48行到第53行中有以下代码:

cvm.h

默认情况下会// 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)的第34883行:

cvm.h

在第basic_schmatrix& set(tint nRow, tint nCol, TC c) throw(cvmexception) { this->_set_at(nRow - CVM0, nCol - CVM0, c); return *this; } 行按Step Into(F11),您将转到函数this->_set_at(nRow - CVM0, nCol - CVM0, c);的定义:

_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); } } 按钮,您将获得结果:

enter image description here

所以为了得到Step Over(F10)nRow=1而不是nCol=1nRow=0,这超出范围nCol=0,你应该写出那一行代码为:

[1,4)