MATLAB: How to use MBUILD to compile a shared library in MATLAB Compiler R2014a

.exportsMATLAB Compiler

In previous MATLAB Compiler versions I used MBUILD in combination with an .exports-file to compile shared libraries, for example:
mbuild myLibrary.c myLibrary.exports
And this worked fine, if I now try to do the same in release R2014a however, I receive the following error:
Error using mbuild (line 164)
Unable to complete successfully.
Unknown file extension '.exports'.

Best Answer

In release R2014a when you want to use MBUILD to build a shared library, the procedure has changed, you will need to:
On Windows
1. No longer use an EXPORTS-file and write a DEF-file instead or use the __declspec(dllexport) in your code, see the following MSDN documentation page for more information about the DEF-file format:
2. Instead of just passing this DEF-file to MBUILD, you need to change the LINKFLAGS, LDEXT and CMDLINE250 by adding the following three options to your call to MBUILD:
LINKFLAGS="$LINKFLAGS /DLL /DEF:_myLibrary.def_" LDEXT=".dll" CMDLINE250="mt -outputresource:$EXE';'2 -manifest $MANIFEST"
Where you replace myLibrary.def with the DEF-file created under point 1 or you can completely omit /DEF:_myLibrary.def_ when making use of __declspec(dllexport).
On Linux
1. On Linux all symbols are exported by default so you basically do not need an EXPORTS-file anyway.
2. To specify that you want to compile a shared library you need to add the following options to the call to MBUILD:
CFLAGS="-fPIC $CFLAGS" LDTYPE="-shared" LDEXT=".so"
MAC
1. As on Linux no EXPORTS-file is needed.
2. To specify that you want to compile a shared library you need to add the following options to the call to MBUILD:
CMDLINE150='' CMDLINE200='$LD $LDFLAGS $OBJS $LINKOPTIM $LINKEXPORT $CLIBS $LINKLIBS -o $EXE' LDEXT='.dylib' LDTYPE='-dynamiclib' LDFLAGS='-arch x86_64 -mmacosx-version-min=$SDKVER -Wl,-syslibroot,$ISYSROOT $LDTYPE $LINKEXPORT -framework CoreFoundation -install_name "@loader_path/$EXENAME$LDEXT"'