难度包括mex文件中的Armadillos库(Matlab + CPP)(错误C2143&错误C2059)

时间:2014-08-13 12:45:31

标签: c++ matlab armadillo

我正在尝试修改一些显示使用mex文件的matlab示例代码。

我试图包含armadillos库(http://arma.sourceforge.net/docs.html)但没有任何成功。

虽然我在这个网站上找到了一个类似的问题;但是,答案没有帮助。所以,我会感激一些帮助。

我通常在其他可视化C ++代码中包含armadillos 没有任何问题,如下所示:

#define ARMA_64BIT_WORD
#include " C:\MIDEA\N4_VD13A_LATEST_20120616\n4\pkg\MrServers\MrImaging\seq\UserLib_DK\armadillo-3-910-0\include\armadillo"
using namespace arma;

但是,当我对“sincall.c”执行相同操作时,它会返回错误(多个实例):

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\cstdlib(21) : error C2143: syntax error : missing '{' before ':' 
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\cstdlib(21) : error C2059: syntax error : ':

我的代码如下所示:

#include "mex.h"
#define MAX 1000

//  #include armadillo
    #define ARMA_64BIT_WORD
    #include " C:\MIDEA\N4_VD13A_LATEST_20120616\n4\pkg\MrServers\MrImaging\seq\UserLib_DK\armadillo-3-910-0\include\armadillo"
    using namespace arma;

/* subroutine for filling up data */
void fill( double *pr, mwSize *pm, mwSize *pn, mwSize max )
{
    mwSize i;  
    /* you can fill up to max elements, so (*pr)<=max */
    *pm = max/2;
    *pn = 1;        // DK: it means that it's 1D array
    for (i=0; i < (*pm); i++) 
    {
      pr[i]=i*(4*3.14159/max);
    }
}


/* gateway function */
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize m, n, max=MAX;
    mxArray *rhs[1], *lhs[1];

    (void) nlhs; (void) plhs;    /* unused parameters */
    (void) nrhs; (void) prhs;

    rhs[0] = mxCreateDoubleMatrix(max, 1, mxREAL);

    /* pass the pointers and let fill() fill up data */
    fill(mxGetPr(rhs[0]), &m, &n, MAX);
    mxSetM(rhs[0], m);
    mxSetN(rhs[0], n);


    /* get the sin wave and plot it */
    mexCallMATLAB(1, lhs, 1, rhs, "sin");
    mexCallMATLAB(0, NULL, 1, rhs, "plot");

    /* cleanup allocated memory */
    mxDestroyArray(rhs[0]);
    mxDestroyArray(lhs[0]);

    return;
}

armadillos头文件的前几行是:

#ifndef ARMA_INCLUDES
#define ARMA_INCLUDES


#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>

此致 DK

0 个答案:

没有答案