It is likely that the code that was generated for a MEX function rather than a standalone target. MEX functions are binaries written C, C++ or Fortran that can be called like a normal MATLAB function. Generating code to produce a MEX function allows two things. First, you can test your generated code in MATLAB because you can call the MEX function from MATLAB like any other function. Look for a file named mul_mex.mex*
after you do code generation and try to call it: mul_mex(1,2)
. The other use for generating a MEX function is that it can often be faster than the MATLAB code from which it was generated. MEX functions are only used in the context of MATLAB.
The parameter emlrtStack*
that you saw appears in MEX generated code to aid in runtime error reporting. It is not present in standalone code that is designed to be run outside of MATLAB.
If you want to use the generated code in Visual Studio, or outside of MATLAB you should choose one of the standalone targets, LIB, DLL, or EXE. This page shows how to change the output type. To summarize, if using the command line you could say:
cfg = coder.config('lib'); %or 'dll' or 'exe'
codegen mul -config cfg -args {1,2}
If using the project interface, you click on the Build
tab and choose static library or shared library in the "Output type" dropdown menu.
I would recommend reading this example that demonstrates how to use a generated DLL in Visual Studio.