Skip to content

InstallingOctave Mac

Linghui edited this page Jul 22, 2012 · 4 revisions

Installing Octave on Mac

We can install everything as either 32-bit. Or as 64-bit. But not a mixture of both. I tried both and ended up with 64-bit homebrew. Since for me, homebrew failed to compile octave as 32-bit only (despite applying the --build32 flag). For that reason its suggested to try the 64-bit homebrew compilation first of all.

64-bit

/*
if you stuck on this step 'brew install graphicsmagick --with-magick-plus-plus '
try this
 brew install --interactive graphicsmagick 
 ./configure --prefix=/usr/local/Cellar/graphicsmagick/1.3.15 CC=clang
 make install
 exit
then 
 brew link graphicsmagick
*/
brew install graphicsmagick --with-magick-plus-plus
brew install fltk --HEAD
brew install octave
echo 'graphics_toolkit ("fltk")' >> ~/.octaverc

Download the Octave packages we need for OpenTLD. Latest versions are at http://octave.sourceforge.net/packages.php.

Misc ^^ depends on GNU Fortran so install it. Currently Mac homebrew won't install libgfortran to your default library path (even with brew link). So we also must create links to libgfortran in /usr/local/lib. Notice that the x86_64/ part of the path isn't required for 32-bit.

brew install gfortran
brew link gfortran
ln -sf /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortran.a /usr/local/lib
ln -sf /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortranbegin.a /usr/local/lib
ln -sf /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortranbegin.so /usr/local/lib
  • Now install the octave packages with octave

    • echo pkg install miscellaneous-1.0.11.tar.gz | octave

    • echo pkg install statistics-1.0.10.tar.gz | octave

    • echo pkg install image-1.0.14.tar.gz | octave

32-bit

Its necessary to install octave with brew install octave --build32. Perhaps this flag result in a 32-bit only Octave on your system. Not actually sure the reason for this so its recommended to try the 64-bit approach instead.

brew install graphicsmagick --with-magick-plus-plus
brew install fltk --HEAD
brew install octave --build32
echo 'graphics_toolkit ("fltk")' >> ~/.octaverc

Download the Octave packages we need for OpenTLD. Latest versions are at http://octave.sourceforge.net/packages.php.

Misc ^^ depends on GNU Fortran so install it. Currently Mac homebrew won't install libgfortran to your default library path (even with brew link). So we also must create links to libgfortran in /usr/local/lib. 64-bit Note: To build the 64-bit libs (without --build32) then link instead to inside the /x86_64 subdirectory of /usr/local/lib/gcc/i686-apple-darwin10/4.2.1.

brew install gfortran --build32
brew link gfortran --build32
ln -s /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/libgfortran.a /usr/local/lib
ln -s /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/libgfortranbegin.a /usr/local/lib
ln -s /usr/local/lib/gcc/i686-apple-darwin10/4.2.1/libgfortranbegin.la /usr/local/lib
  • Now install the octave packages with octave

    • echo pkg install miscellaneous-1.0.11.tar.gz | octave

    • echo pkg install statistics-1.0.10.tar.gz | octave

    • echo pkg install image-1.0.14.tar.gz | octave

Possible errors

Architecture error

Usually its architecture mismatch. A mixture of 32-bit and 64-bit libraries

ld: warning: in /Applications/Octave.app/Contents/Resources/bin/octave-3.4.0, file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in /Applications/Octave.app/Contents/Resources/lib/octave-3.4.0/liboctinterp.dylib, file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in /Applications/Octave.app/Contents/Resources/lib/octave-3.4.0/liboctave.dylib, file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in /Applications/Octave.app/Contents/Resources/lib/octave-3.4.0/libcruft.dylib, file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in /Applications/Octave.app/Contents/Resources/lib/libfftw3f.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in /usr/local/lib/libgfortranbegin.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in /usr/local/lib/libgfortran.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: in /usr/lib/gcc/i686-apple-darwin10/4.2.1/libgcc.a, file was built for unsupported file format which is not the architecture being linked (x86_64)

Since the required library cant be loaded (architecture mismatch). Then subsequent undefined symbol errors may obscure the first error

Undefined symbols:
  "_mxGetM", referenced from:
      _mexFunction in distance.o
      _mexFunction in distance.o
  "_mxGetN", referenced from:
      _mexFunction in distance.o
      _mexFunction in distance.o
  "_mexPrintf", referenced from:
      _mexFunction in distance.o
      _mexFunction in distance.o
      _mexFunction in distance.o
      _mexFunction in distance.o
  "_mxCreateDoubleMatrix", referenced from:
      _mexFunction in distance.o
  "_mxGetPr", referenced from:
      _mexFunction in distance.o
      _mexFunction in distance.o
      _mexFunction in distance.o
      _mexFunction in distance.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

When such mismatch occurs then its usually easier to recompile just the dependant libraries rather than Octave itself. Ie swap over the openCV or GNU Fortran as necessary.

Run octave --version to check the architecture

janitors-Mac-mini:predator id$ octave --version
GNU Octave, version 3.4.0
Copyright (C) 2011 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

Octave was configured for "x86_64-apple-darwin10.6.0".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/help-wanted.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.

GNU Plot Error

Shouldn't happen anymore if you follow the instructions ^^ above exactly. Anything referring to the gnuplot program executable. For example gnuplot not found, failed exec(), etc.

Or perhaps this error https://gist.github.com/977731

gnuplot> C
         ^
         line 0: invalid command

Its because Octave is configured to use GNU Plot by default. OpenTLD currently uses the fltk graphics backend. Add this line to your ~/.octaverc

echo 'graphics_toolkit ("fltk")' >> ~/.octaverc

Octave.app

This isn't currently recommended. But remains a valid alternative to the homebrew version.

The draw is a faster way to install Octave on the Mac, by downloading the official binary. A drawback of Octave.app is that configuration and load paths / library paths don't seem to as good as the homebrew version. Also, this distribution is labeled i386. However in truth Octave.app actually contains both 32-bit and x86_64 versions (thanks to Xcode Universal Binary). OS X will probably select to run octave as x86_64 by default when you launch it. So this i386 label is likely to be confusing to some. The dyld loading of opentld dependencies (Open CV and GNU Fortran) occurs independently and after octave is loaded by Mac OS X. Its easily broken if any of them are 32-bit binaries since octave was selected at launch to be 64-bit.

  • Download Octave.app from Sourceforge

    • ln -sf /Applications/Octave.app/Contents/Resources/bin/octave ~/bin/

    • This is assuming that ~/bin is on your $PATH.

    • Only link directly to the octave binary. NEVER add .../Resources/bin/ to your $PATH.