I've been trying to recompile some old code I had on my new machine, but it fails consistently. I have reduced the problem down to a more or less minimal example.
The code:
#include <math.h>
#include <mat.h>
#include <matrix.h>
int main(int argc, char *argv[]) {
const char *name;
int ndim;
MATFile *pmat;
mxArray *pa;
pmat = matOpen("../orders/order_fractal_C1.mat", "r");
pa = matGetNextVariable(pmat, &name);
ndim = mxGetNumberOfDimensions(pa);
return 0;
}
Compiled with the command
$MATLABROOT/bin/mex -v -f ~/matopts.sh CFLAGS="" -output test test.c
The matopts.sh file points mex to using gcc-5 (installed via homebrew).
The code compiles without errors or warnings, but on executing ./test I get
dyld: lazy symbol binding failed: Symbol not found: >_mxGetNumberOfDimensions_700 Referenced from: /Users/keith/Dropbox/Code/sphere/newparallel/C/./test Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _mxGetNumberOfDimensions_700 Referenced from: /Users/keith/Dropbox/Code/sphere/newparallel/C/./test Expected in: /usr/lib/libSystem.B.dylib
If I don't include the last line of code, all is well. What is going wrong? Why does it "expect" the symbol to be in libSystem.B.dylib, and not in matrix.h?
EDIT: The whole matopts.sh file is rather large, all I did was change
CC='gcc'
to
CC='gcc-5'
in two instances, so it would not use clang.
EDIT 2: I decided to go back to using clang, figuring that it is probably best to just accept the way Matlab wants to do things.
Now I can get it to work, but only when executing the command from within Matlab, either by compiling it as a mexFunction
and calling the function in Matlab, or by compiling it with -client engine
and then running with !./test
.
If I try to run it from outside Matlab, however, I get the same error as before.
#include <math.h> #include <mat.h> #include <matrix.h>
– KeithWMedit
under your post. – too honest for this sitelibSystem.B.dylib
in a reachable dir, because your program wants it in a dynamic lib. – LPs-largeArrayDims
(note case) to yourmex
command. – chappjc