mex wont compile propperly, missing mexFunction?

5 次查看(过去 30 天)
I am trying to compile a mex file from a .c file, but I keep getting an error:
>> mex arrayProduct.c
LINK : error LNK2001: unresolved external symbol mexFunction
C:\Users\thor\AppData\Local\Temp\mex_ibRb0h\templib.x : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Link of 'arrayProduct.mexw64' failed.
Error using mex (line 206)
Unable to complete successfully.
I looked through the code and I searched online and I cannot find the problem. The actual .c file is at the end of this post. It would be great if someone else could confirm this error also happens for them or help me solve it
Thanks guys!
/*==========================================================
* arrayProduct.c - example in MATLAB External Interfaces
*
* Multiplies an input scalar (multiplier)
* times a 1xN matrix (inMatrix)
* and outputs a 1xN matrix (outMatrix)
*
* The calling syntax is:
*
* outMatrix = arrayProduct(multiplier, inMatrix)
*
* This is a MEX-file for MATLAB.
* Copyright 2007-2010 The MathWorks, Inc.
*
*========================================================*/
/* *========================================================*/
/* libraries for making Mex files */
/* *========================================================*/
#include "mex.h"
/* *========================================================*/
/* The gateway function */
/* *========================================================*/
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double multiplier; /* input scalar */
double *inMatrix; /* 1xN input matrix */
size_t ncols; /* size of matrix */
double *outMatrix; /* output matrix */
/* check for proper number of arguments */
/* nrhs is number of input arguments */
if(nrhs!=2) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nrhs","Two inputs required.");
}
/* nlhs is number of output arguments */
if(nlhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nlhs","One output required.");
}
/* make sure the first input argument is scalar */
if( !mxIsDouble(prhs[0]) ||
mxIsComplex(prhs[0]) ||
mxGetNumberOfElements(prhs[0])!=1 ) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notScalar","Input multiplier must be a scalar.");
}
/* check that number of rows in second input argument is 1 */
if(mxGetM(prhs[1])!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notRowVector","Input must be a row vector.");
}
/* get the value of the scalar input */
multiplier = mxGetScalar(prhs[0]);
/* create a pointer to the real data in the input matrix */
inMatrix = mxGetPr(prhs[1]);
/* get dimensions of the input matrix */
ncols = mxGetN(prhs[1]);
/* create the output matrix */
plhs[0] = mxCreateDoubleMatrix(1,(mwSize)ncols,mxREAL);
/* get a pointer to the real data in the output matrix */
outMatrix = mxGetPr(plhs[0]);
/* call the computational routine */
arrayProduct(multiplier,inMatrix,outMatrix,(mwSize)ncols);
}
/* *========================================================*/
/* The computational routine */
/* *========================================================*/
void arrayProduct(double x, double *y, double *z, mwSize n)
{
/*Declares i*/
mwSize i;
/* multiply each element y by x */
for (i=0; i<n; i++)
{
z[i] = x * y[i];
}
}

回答(1 个)

Jan
Jan 2013-7-20
编辑:Jan 2013-7-20
I get a different warning under Matlab 2009a/64 MSVC SDK7.0:
arrayProduct.c(60) : warning C4013: 'arrayProduct' undefined; assuming extern returning int
arrayProduct.c(66) : error C2371: 'arrayProduct' : redefinition; different basic types
This problem is solved by adding the prototype:
void arrayProduct(double x, double *y, double *z, mwSize n);
I assume you have a completely other problem, e.g. you do not compile the file you think you do. Is the parent folder of arrayProduct.c the current folder?
  3 个评论
Jan
Jan 2013-7-20
And this is the file shown above? Please test this again, because it obviously contains a valid mexFunction.
Have you been able to compile any other file yet?
Thor
Thor 2013-7-21
Actually I have nto been able to compile any other files, even official ones from published articles which I know are working on my advisors computer. So I suppose the problem must be with by computer, but I cant figure out what it is ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by