MATLAB: Unable to build a shared library

matlab buildershared library

I run R2011b on Mac OSX10.6.8. When I try the users' guide example of shared library compilation and execute the command:
>> mbuild matrixdriver.c -L. -lmatrix -I. -v
the build process terminates immediatly with no error messages, just:
----------------------------------------------------------------
-> mbuildopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /Users/dan/.matlab/R2011b/mbuildopts.sh
----------------------------------------------------------------
-> TMW_ROOT = /Applications/MATLAB_R2011b.app
-> CC = gcc-4.2
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -I/Applications/MATLAB_R2011b.app/extern/include -DUNIX -DX11
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2011b.app/runtime/maci64 -lmwmclmcrrt
arguments =
-> LD = gcc-4.2
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bind_at_load
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
arguments = -L.
----------------------------------------------------------------
-> gcc-4.2 -c -I. -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -I/Applications/MATLAB_R2011b.app/extern/include -DUNIX -DX11 -O2 -DNDEBUG "matrixdriver.c"
-> gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bind_at_load -framework CoreFoundation -L. -o matrixdriver.app/Contents/MacOS/matrixdriver matrixdriver.o -L/Applications/MATLAB_R2011b.app/runtime/maci64 -lmwmclmcrrt -lmatrix
----------------------------------------------------------------
The directory matrixdriver.app has been created and the files matrixdriver.app/Contents/MacOS/applauncher matrixdriver prelaunch
are also created.
I have set correctly the DYLD_LYBRARY_PATH for MCR.
When I try to execute in the Terminal window the command:
> .../work/libexample/matrixdriver.app/Contents/MacOS/matrixdriver
I get the message:
dyld: Library not loaded: @loader_path/libmatrix.dylib
Referenced from: .../work/libexample/matrixdriver.app/Contents/MacOS/matrixdriver
Reason: no suitable image found. Did find:
/System/Library/Frameworks/JavaVM.framework/JavaVM/libmatrix.dylib: stat() failed with errno=20
Trace/BPT trap
apparently the DYLD lib has not been correctly linked.
Can you provide any suggestion? best regards

Best Answer

Are you running the example on this page? If yes, you should have also run the following command to generate libmatrix.dylib:
mcc -B csharedlib:libmatrix addmatrix.m multiplymatrix.m
eigmatrix.m -v
You probably need to add the directory containing this library also to DYLD_LYBRARY_PATH.