MATLAB: Am I unable to use the MEX API in external functions of applications created with MATLAB Compiler 4.0 (R14)

apiccocompilerexternalMATLAB Compilermccmexmex.hmexapi

I am generating a stand-alone executable or shared library using MATLAB Compiler 4.0 (R14). For one of the M-functions, I have used the %#external compiler pragma, specifiying that this function is to be replaced with a user-created C/C++ function in the deployed application. In my external C/C++ code, I have included "mex.h" so that I am able to use the MEX API functions.
When trying to compile using the MCC function, I received link errors similar to the following:
undefined reference to '_mexErrMsgTxt'
where "_mexErrMsgTxt" could be replaced with function in the MEX API.

Best Answer

This enhancement has been incorporated in Release 2006a (R2006a). For previous product releases, read below for any possible workarounds:
The MEX API is not supported in C/C++ external functions. This is mentioned in the MATLAB Compiler documentation, which can be viewed by copying the following to the MATLAB command prompt:
web([docroot,'/toolbox/compiler/mcc_command13.html#1001757'])
Specifically, note the following line from the documentation regarding the external function:
"This function must conform to the same interface as the Compiler-generated code."
The interface referred to above does not include the MEX API interface.
We are currently investigating the possibility of supporting the MEX API in external functions for a future release of the MATLAB Compiler.
Related Question