0
votes

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.

1
It seems I messed up the opening bit of the code, and I can't edit it either, but it should read #include <math.h> #include <mat.h> #include <matrix.h>KeithWM
Just click edit under your post.too honest for this site
matrix.h could give you the prototype of function, but the function must be somewhere... in a static lib, in a shared lib, or in our source code. You must put libSystem.B.dylib in a reachable dir, because your program wants it in a dynamic lib.LPs
Of course, I should have known that matrix.h would not contain the function. But should I expect libSystem.B.dylib to actually contain mex-functions?KeithWM
You just need to add -largeArrayDims (note case) to your mex command.chappjc

1 Answers

0
votes

You need to add -largeArrayDims (note the case) to your mex command.

If you are still having trouble, be sure you are not defining MX_COMPAT_32 anywhere.