Why 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)?

21 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Feb 2010
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

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!