Nitsorn Wongsajjathiti
Nitsorn Wongsajjathiti

Reputation: 317

error LNK2001: unresolved external symbol mexFunction

I am trying to create a MEX file for a simple C function as follows:

#include <math.h>
#include <mex.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
int main()
{
    int x;
    int c;
    c=2;
    x=4;
    mexprintf ("the value for y is %d",c*x*x);

}

I saved the file as quad.c But on Matlab, when I use the mex function

 mex quad.c

I receive an error:

 >> mex quadfinal.c
LINK : error LNK2001: unresolved external symbol mexFunction 
C:\Users\Oatmeel\AppData\Local\Temp\mex_UGPnwF\templib.x : fatal error LNK1120: 1 unresolved externals 

C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'quadfinal.mexw64' failed. 

Error using mex (line 206)
Unable to complete successfully.

I properly included the mexFunction. I dont know where I am going wrong. Please help!

Upvotes: 0

Views: 3670

Answers (1)

Rafael Monteiro
Rafael Monteiro

Reputation: 4549

Replace this:

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
int main()

By this:

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])

Note there is no ; at the end.

EDIT: also, mexprintf should be mexPrintf.

Upvotes: 1

Related Questions