mex wont compile propperly, missing mexFunction?

조회 수: 1 (최근 30일)
Thor
Thor 2013년 7월 20일
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