Unresolved External errors when compiling an S-Funtion in VS2008

2 views (last 30 days)
[EDIT: 20110609 23:06 CDT - reformat - WDR]
I am trying to compile an S-Function using VS 2008.
I have followed the instructions to compile an s-function from
I have included the relevant libraries (libmx.lib libmat.lib libmex.lib) their linking directories as well as included "mex.h". However, I still get the following errors from the compiler:
1>Control.obj : error LNK2001: unresolved external symbol _mexWarnMsgTxt
1>Control.obj : error LNK2001: unresolved external symbol _mexCallMATLAB
1>Control.obj : error LNK2001: unresolved external symbol _mxCreateString
1>Control.obj : error LNK2001: unresolved external symbol _mxGetClassID
1>Control.obj : error LNK2001: unresolved external symbol _mxGetPr
1>Control.obj : error LNK2001: unresolved external symbol _mxCreateDoubleMatrix_730
1>Control.obj : error LNK2001: unresolved external symbol _mxIsNumeric
1>Control.obj : error LNK2001: unresolved external symbol _mxIsComplex
1>Control.obj : error LNK2001: unresolved external symbol _mxGetN
1>Control.obj : error LNK2001: unresolved external symbol _mxGetM
1>Control.obj : error LNK2001: unresolved external symbol _mexErrMsgTxt
1>Control.obj : error LNK2001: unresolved external symbol _mxCalloc

Accepted Answer

Richard Beranek
Richard Beranek on 28 Apr 2011
I ultimately tracked the problem down. The issue was that I was compiling on a 64 bit system. This meant I had to configure the compiler to target an x64 platform (not use default win32) as well as recompile my own libraries to target an x64 platform. This has resolved the issue and I am able to compile my s-function in both visual studio and using 'mex' command in matlab.

More Answers (1)

Kaustubha Govind
Kaustubha Govind on 26 Apr 2011
Have you also ensured step 4 (Add "$MATLABROOT\extern\lib\win32\microsoft" in the options Linker->General->Additional Library Directories). Note that if you have 64-bit MATLAB, you need to swap win32 with win64. Double-check that the relevant libraries are present in whatever folder you add to the directories list.
  2 Comments
Richard Beranek
Richard Beranek on 26 Apr 2011
Yes I am running a 64-bit system and I have switched the include and library directories for the 64-bit locations.
Additionally VS spits out an error if it cannot find the lib files that are added in the dependencies. So it does not seem like that is the issue.
Kaustubha Govind
Kaustubha Govind on 26 Apr 2011
Have you also configured MSVC to target 64-bit platforms (I think it tries to build a 32-bit DLL by default). See http://msdn.microsoft.com/en-us/library/9yb4317s%28v=vs.80%29.aspx
Also, set .mexw64 as the extension.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!