MATLAB: Do I receive a “LINK : error LNK2001: unresolved external symbol mexFunction” error when I attempt to mex a C++ source file using MATLAB 7.8 (R2009a)

3264errorlinklinkerMATLABmex

I am written a C++ MEX file which calls functions that are located in other C++ source files. When I attempt to mex the file which contains the gateway function, I receive the following error:
LINK : error LNK2001: unresolved external symbol mexFunction
C:\DOCUME~1\E445337\LOCALS~1\TEMP\MEX_5Y~1\templib.x : fatal error LNK1120: 1 unresolved externals
E:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Link of 'InPassage.mexw32' failed.
??? Error using ==> mex at 218
Unable to complete successfully.

Best Answer

The error received is a linker error which indicates that the C++ source file that is being MEXed does not contain the MEX gateway function "mexFunction".
To create a MEX file using source code that is present in multiple source files, provide all the source files as input to the MEX function. For example, if you have the following source files:
fileContaininingMEXGateway.cpp
sourceFile1.cpp
sourcefile2.cpp
the MEX command to be used to create a a MEX file is shown below:
mex -v fileContaininingMEXGateway.cpp sourceFile1.cpp sourcefile2.cpp
Related Question