MATLAB: Do I receive a warning about ‘_mainCRTStartup’ and a failure to compile when I attempt to create a C shared library using the MATLAB Compiler

MATLAB Compiler

I'm trying to create a C shared library using the MATLAB Compiler using a command similar to the following:
mcc -B csharedlib:libmatrix myFunc.m
However, I receive the following error:
Creating library libmatrix.lib and object libmatrix.exp
libmatrix.dll : warning LNK4086: entrypoint "_mainCRTStartup" is not __stdcall with 12 bytes of arguments; image may not run
LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
libmatrix.dll : fatal error LNK1120: 1 unresolved externals

Best Answer

It is likely that someone has modified your compopts.bat file, adding a line which eliminates the DOS window from appearing in a compiled application. However, this line causes the error you are encountering when you use the MATLAB Compiler to create a C shared library.
To resolve this issue, type the following commands at the MATLAB command prompt:
cd(prefdir)
edit compopts.bat
In compopts.bat, you should see a line similar to the following:
set LINKFLAGS=%LINKFLAGS% /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup.
Change the word 'set' to 'rem' (without the quotes) and then save the file. This will allow the MCC command to create the shared library successfully.