How can I use MBUILD to compile a shared library in MATLAB Compiler R2014a?

10 views (last 30 days)
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: Error using mbuild (line 164)
Unable to complete successfully.
Unknown file extension '.exports'.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Jun 2021
Edited: MathWorks Support Team on 30 Jun 2021
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"'

More Answers (0)

Categories

Find more on Manage Products in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

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

Start Hunting!