MATLAB: Does mclInitial​izeApplica​tion() fail if I use different compiler flags than MBUILD does in MATLAB Compiler 4.3 (R14SP3)

MATLAB Compiler

I used g++ directly to build the driver application in the MatrixDriver example in the C++ Shared Library Example section of the MATLAB Compiler 4.3 (R14SP3):
mcc -B cppsharedlib:libmatrixp addmatrix.m mutiplymatrix.m eigmatrix.m
!g++ -o matrixdriver -L. -lmatrixp -I$MATLAB/extern/include matrixdriver.cpp
However, when I execute the resulting application:
!./matrixdriver
it fails silently with no error message. I have traced this to a failure in the mclInitializeApplication() call.

Best Answer

Use MBUILD as specified in the MatrixDriver example. This links against several libraries and defines several macros that your g++ invocation does not. Using a verbose build lists these options:
mbuild -v matrixdriver.cpp -L. -lmatrixp -I.
For example, the MATLAB Compiler 4.3 (R14SP3) with gcc/g++ on 64-bit Linux uses the following g++ command:
g++ -c -I/devel/archive/R14/sp3/ship/unix/dist/extern/include/cpp -I/devel/archive/R14/sp3/ship/unix/dist/extern/include -DUNIX -DX11 -ansi -D_GNU_SOURCE -pthread -DGLNXA64 -DGCC -I. -O -DNDEBUG matrixdriver.cpp
g++ -O -pthread -L. -o matrixdriver matrixdriver.o -Wl,-rpath-link,/devel/archive/R14/sp3/ship/unix/dist/bin/glnxa64 -L/devel/archive/R14/sp3/ship/unix/dist/bin/glnxa64 -lmwmclmcrrt -lm -lmatrixp
If using your own compiler directly, as with gcc/g++ from the command line, or a 3rd Party IDE on Windows, you must link against the same libraries and define the same macros as MBUILD does for your configuration.