Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2008-10-23
年龄: 41
帖子: 2
声望力: 0 ![]() |
![]()
使用matlab与c混合编程时,一模一样从书上抄的例子,却总是包错
代码如下: #include "mex.h" #define A_IN 0 #define B_IN 1 #define C_OUT 0 #define D_OUT 1 extern void addmlt(const int MA,const int NA,const double *A, const int MB,const int NB,const double *B,double *C,double *D) { int i,j,k; for(i=0;i<MA;i++) for(j=0;j<NA;j++){ C[i+j*MA]=A[i+j*MA]+B[i+j*MB]; } for(i=0;i<MA;i++){ for(j=0;j<NB;j++){ D[i+j*MA]=0.0; for(k=0;k<NA;k++){ D[i+j*MA]=D[i+j*MA]+(A[i+k*MA]*B[k+j*MB]); } } } } void mexFunction( int nlhs, // Number of left hand side (output) arguments mxArray *plhs[], // Array of left hand side arguments int nrhs, // Number of right hand side (input) arguments const mxArray *prhs[] // Array of right hand side arguments ) { double *A,*B,*C,*D; int MA,NA,MB,NB,MC,NC,MD,ND; if(nrhs!=2) mexErrMsgTxt("two input required"); else if(nlhs>2) mexErrMsgTxt("too many output argument."); if(!mxlsDouble(prhs[A_IN])||mxlsComplex(prhs[A_IN])|| !mxlsDouble(prhs[B_IN])||mxlsComplex(prhs[B_IN])){ mexErrMsgTxt("input must be double"); } MA=mxGetM(prhs[A_IN]); NA=mxGetN(prhs[A_IN]); MB=mxGetM(prhs[B_IN]); NB=mxGetN(prhs[B_IN]); if(MA!=MB||NA!=NB) mexErrMsgTxt("dimension of inputs should be same."); if(NA!=MB) mexErrMsgTxt("column of a shoulde be equal to row of b."); MC=MA; NC=NA; MD=MA; ND=NB; plhs[C_OUT]=mxCreateDoubleMatrix(MC,NC,mxREAL); plhs[D_OUT]=mxCreateDoubleMatrix(MD,ND,mxREAL); A=mxGetPr(prhs[A_IN]); B=mxGetPr(prhs[B_IN]); C=mxGetPr(plhs[C_OUT]); D=mxGetPr(plhs[D_OUT]); addmlt(MA,NA,A,MB,NB,B,C,D); } 出错误如下: Compiling... addmlt.c C:\MATLAB6p5\work\addmlt\addmlt.c(44) : warning C4013: 'mxlsDouble' undefined; assuming extern returning int C:\MATLAB6p5\work\addmlt\addmlt.c(44) : warning C4013: 'mxlsComplex' undefined; assuming extern returning int addmlt.obj - 0 error(s), 2 warning(s) -------------------- Linking... Creating library addmlt.lib and object addmlt.exp addmlt.obj : error LNK2001: unresolved external symbol _mxlsComplex addmlt.obj : error LNK2001: unresolved external symbol _mxlsDouble addmlt.dll : fatal error LNK1120: 2 unresolved externals Error executing link.exe. addmlt.dll - 3 error(s), 0 warning(s) -------------------- 求高手献玉,晚辈不胜感激/ |
![]() |
![]() |