MEX link failed

2 vues (au cours des 30 derniers jours)
Lofi
Lofi le 21 Oct 2011
I met link failed problem when I compiling mex code. I'm using matlab r2011a, with win7, and I got the same result under linux.
Error Message:
D:\Study Stuff\Robust PCA\Robust PCA\src\ENV\packages\PROPACK>mex reorth_mex.c
Writing library for reorth_mex.mexw32
*c:\users\lofi\appdata\local\temp\mex_ufvcxe\reorth_mex.obj .text: undefined reference to '_reorth_'*
D:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'reorth_mex.mexw32'
failed.
Source Code:
#include <string.h>
#include "mex.h"
/* Template for reorth: */
void reorth_(int *n, int *k, double *V, int *ldv, double *vnew,
double *normvnew, double *index, double *alpha, double *work,
int *iflag, int *nre);
/* Here comes the gateway function to be called by Matlab: */
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
int n, k1, k, imethod, inre;
double *work;
if (nrhs != 6)
mexErrMsgTxt("reorth requires 6 input arguments");
else if (nlhs < 2)
mexErrMsgTxt("reorth requires at least 2 output arguments");
n = mxGetM(prhs[0]); /* get the dimensions of the input */
k1 = mxGetN(prhs[0]);
k = mxGetM(prhs[3]) * mxGetN(prhs[3]);
/* Create/allocate return argument, a 1x1 real-valued Matrix */
plhs[0]=mxCreateDoubleMatrix(n,1,mxREAL);
plhs[1]=mxCreateDoubleMatrix(1,1,mxREAL);
if (nlhs>2)
plhs[2]=mxCreateDoubleMatrix(1,1,mxREAL);
work = mxCalloc(k,sizeof(double));
memcpy(mxGetPr(plhs[0]),mxGetPr(prhs[1]), n*sizeof(double));
memcpy(mxGetPr(plhs[1]),mxGetPr(prhs[2]), sizeof(double));
imethod = (int) mxGetScalar(prhs[5]);
reorth_(&n, &k, mxGetPr(prhs[0]), &n, mxGetPr(plhs[0]),
mxGetPr(plhs[1]), mxGetPr(prhs[3]), mxGetPr(prhs[4]),
work,&imethod,&inre);
if (nlhs>2)
*(mxGetPr(plhs[2])) = (double) inre*k;
mxFree(work);
}

Réponses (1)

Jan
Jan le 21 Oct 2011
Where is the definition of reorth_? It must be either included in reorth_mex.c or added to the mex command.

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by