compiling for maci46

Asked by Jeff Gauthier

I'm using matlab 2008a on an 64-bit intel mac, but there are no mex files that end in ".maci64". How do I compile them myself?

Question information

Language:
English Edit question
Status:
Solved
For:
Matlab BGL Edit question
Assignee:
No assignee Edit question
Solved by:
Jeff Gauthier
Solved:
Last query:
Last reply:
Revision history for this message
David Gleich (dgleich) said :
#1

1) Download boost 1.36.0

2) Make a new compile-macosx-intel-64-large.sh file with these contents and *** Update the boost_dir to where you downloaded 1.36.0 ***

#!/bin/bash -e

BOOST_DIR=${HOME}/dev/lib/boost_1_36_0/
YASMIC_DIR=.

source ccfiles.sh
OFILES=`echo ${CCFILES} | sed -e 's/\.cc/\.o/g'`

CFLAGS="-O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I${BOOST_DIR} -I${YASMIC_DIR}"
#CFLAGS="-g -W -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I${BOOST_DIR} -I${YASMIC_DIR}"

function echocmd {
 echo $@
 $@
}

for file in ${CCFILES}; do
 echocmd g++ $CFLAGS $file
done

echocmd ar rc libmbgl-macosx-intel-64-large.a ${OFILES}

echocmd rm ${OFILES}

3) Add the following line to the big case statement in private/compile.m

    case 'MACI64'
        libname = 'mbgl-macosx-intel-64-large';

4) In theory, you should be able to run from the terminal:

[matlab_bgl] $ cd libmbgl
[matlab_bgl/libmbgl] $ sh compile-macosx-intel-64-large.sh

and everything will compille

Then in matlab:

>> cd matlab_bgl % or wherever it is
>> cd private
>> compile

And evrything should work.

Revision history for this message
Jeff Gauthier (gauthier-salk) said :
#2

Thank you for the detailed instructions. Everything went well until the very last step.

I downloaded boost 1.36.0 from http://www.boost.org/users/history/ . Running the sh script seemed to work as expected:

-% sh compile-macosx-intel-64-large.sh
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. components.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. max_flow.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. orderings.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. searches.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. shortest_path.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. spanning_trees.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. statistics.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. layouts.cc
g++ -O2 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I/Developer/usr/lib/boost_1_36_0/ -I. planar.cc
ar rc libmbgl-macosx-intel-64-large.a components.o max_flow.o orderings.o searches.o shortest_path.o spanning_trees.o statistics.o layouts.o planar.o
rm components.o max_flow.o orderings.o searches.o shortest_path.o spanning_trees.o statistics.o layouts.o planar.o

But compiling in matlab failed with this error:

>> cd matlab_bgl/private
>> compile
mex -O CFLAGS="\$CFLAGS -Wall" -I../libmbgl/include -L../libmbgl -lmbgl-macosx-intel-64-large astar_search_mex.c
ld warning: in ../libmbgl/libmbgl-macosx-intel-64-large.a, file is not of required architecture
Undefined symbols:
  "_astar_search_hfunc_visitor", referenced from:
      _mexFunction in astar_search_mex.o
  "_astar_search", referenced from:
      _mexFunction in astar_search_mex.o
  "_astar_search_hfunc", referenced from:
      _mexFunction in astar_search_mex.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

    mex: link of ' "astar_search_mex.mexmaci64"' failed.

??? Error using ==> mex at 207
Unable to complete successfully.

Error in ==> compile at 105
     eval(mexstr);

I don't know how to interpret this. Any thoughts on what to try next?

Revision history for this message
David Gleich (dgleich) said :
#3

In the

compile-macosx-intel-64-large.sh

Modify the flags to include

-arch x86_64

So you should have

CFLAGS="-O2 -arch x86_64 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I${BOOST_DIR} -I${YASMIC_DIR}"

Then let me know what happens, after starting over.

It looks like g++ on the mac doesn't compile for the 64-bit platform by default.

David

Revision history for this message
Jeff Gauthier (gauthier-salk) said :
#4

Success! But I had to make one more change, documented here for future reference.

The case for MACI64 should also have the large_arrays flag, like this:

    case 'MACI64'
        libname = 'mbgl-macosx-intel-64-large';
        large_arrays = 1;

With that, I got a small bit of example code to work:

>> clustering_coefficients(sparse(ones(5)))

ans =

     1
     1
     1
     1
     1

As I begin to use the code, I'll update this thread if anything goes wrong that seems specific to 64-bit intel macs.

Thank you for your help!

--Jeff

Revision history for this message
Salvatore Lattanzio (lat010) said :
#5

Hello,

I'm using matlab R2017a on an 64-bit intel mac. I run the same sh script as reported above in the terminal, but I keep getting these two errors:
1)/Users/salvatorelattanzio/Documents/boost_1_36_0/boost/graph/make_maximal_planar.hpp:148:31: error:
call to 'next' is ambiguous
2) rm: planar.o: No such file or directory
Is there a way to fix this? Thank you for your help.

Best
Sal

Revision history for this message
Keith (hesken) said :
#6

Sal,

I'm not sure if you're still working on this, but I managed to work around the issue you're having. The fix was to replace every call to 'next' within the boost directory with 'boost::next'

Somehow there's an ambiguity because there's a standard c++ next() function and one defined within boost, and the code can't decide which it should use, so you need to tell it which to use.

I performed the replacement by running " rpl -R 'next(' 'boost::next(' * " from inside the boost/graph/ directory.

After doing so, I actually ran into another issue, which was that, in boost/graph/push_relabel_max_flow.hpp there seems to be a bug. On line 430, topo_boost::next(n) is declared. The declaration should actually be topo_next(n), as topo_boost isn't a class, and topo_next is called later in the code, but was never defined.

Once I corrected these two errors, everything compiled accordingly.

Cheers,
Keith

Revision history for this message
Klemens Esterle (klemens12) said :
#7

Hi Keith,

I could not compile the library, although I added the boost-namespace in the graph directory. Could you send me your matlab-bgl directory as a zipped file?

Many thanks
Klemens

Revision history for this message
Nate Roberts (nroberts5) said :
#8

Just because this really helped me today, I wanted to summarize what worked on macOS Mojave (10.14.6) with Matlab_R2017b. I'll summarize the steps from above with the changes incorporated.

1) Download boost 1.36.0

2) Make a new compile-macosx-intel-64-large.sh file with these contents and *** Update the boost_dir to where you downloaded 1.36.0 ***

#!/bin/bash -e

BOOST_DIR=${HOME}/dev/lib/boost_1_36_0/
YASMIC_DIR=.

source ccfiles.sh
OFILES=`echo ${CCFILES} | sed -e 's/\.cc/\.o/g'`

CFLAGS="-O2 -arch x86_64 -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I${BOOST_DIR} -I${YASMIC_DIR}"
#CFLAGS="-g -W -DMATLAB_BGL_LARGE_ARRAYS -fPIC -c -I${BOOST_DIR} -I${YASMIC_DIR}"

function echocmd {
 echo $@
 $@
}

for file in ${CCFILES}; do
 echocmd g++ $CFLAGS $file
done

echocmd ar rc libmbgl-macosx-intel-64-large.a ${OFILES}

echocmd rm ${OFILES}

3) Add the following line to the big case statement in private/compile.m

    case 'MACI64'
        libname = 'mbgl-macosx-intel-64-large';
        large_arrays = 1;

4) Find and replace 'next(' with 'boost::next(' in boost_1_36_0/boost/graph
I used Sublime Text 3 find and replace in directory (cmd+shift+f) with the expression: (?<!\w)next\(
This ensures you don't accidentally split a string that shouldn't be changed and cause a new problem (as I think happened with Keith above)

5) In theory, you should be able to run from the terminal:

[matlab_bgl] $ cd libmbgl
[matlab_bgl/libmbgl] $ sh compile-macosx-intel-64-large.sh

and everything will compille

5.5) For some reason, my compile still failed and I had to then go and manually edit the following file/line: ./yasmic/boost_mod/is_straight_line_drawing.hpp:188
    Change "after = next(a_itr);" to "after = boost::next(a_itr);"
then: `sh compile-macosx-intel-64-large.sh` again

6) Then in matlab:

>> cd matlab_bgl % or wherever it is
>> cd private
>> compile

And everything should work.