If you’re anything like me, and you rely on Octave in your work, then not having a working copy can be very frustrating.
I stumbled on, not one, but two issues plaguing Octave in Snow Leopard.
First, it appears that installing Octave via macports is busted. Actually, you’ll get stuck while building gcc45. There’s already an open macports bug for this (see the huge list of open issues), so it’ll probably get solved soon. I don’t normally install Octave via macports, but when I got stuck installing packages I tried to install via this route.
Second, when you try installing packages from octave forge from within the pre-made Octave binary, the build fails with some messages about mismatched architectures. This is because GCC is defaulting to build x86_64, but Octave is built as i386 for the time being.
I typically prefer to use the pre-made binaries. It’s the quickest route to getting Octave up and running on your system, and installing packages is quite painless. So, I decided to hack around until I could determine a quick solution to the problem. Here’s my solution:
- Open /Applications/Octave.app/Contents/Resources/bin/mkoctfile
/usr/local/bin/mkoctfile - Change CFLAGS, FFLAGS, CPPFLAGS, CXXFLAGS, and LDFLAGS so that they all contain -arch i386. I put it at the beginning, so it looks like this:
CFLAGS="-arch i386 -I${ROOT}/include[...]
FFLAGS="-arch i386 -I${ROOT}/include[...]
CPPFLAGS="-arch i386 -I${ROOT}/include[...]
CXXFLAGS="-arch i386 -I${ROOT}/include[...]
LDFLAGS="-arch i386 -L${ROOT}/lib[...]
I hope this helps someone. I’m pretty sure it’s not the correct way to solve the problem, but I just don’t have the time right now to figure out the proper solution, submit a patch, etc.
Update 20090924—Changed location of mkoctfile. On my main machine, it’s apparent that I still have some holdovers from when I was messing around with the macports version of Octave. While setting up my laptop with the Octave.app package, I found out where mkoctfile was supposed to live. Apologies for the error.




September 29th, 2009 at 11:38 pm
I get the following error (I have a symlink to mkoctfile in /bin):
octave-3.2.2:1> pkg install /Users/xnk/Downloads/octcdf-1.0.13.tar.gz
warning: creating installation directory /Users/xnk/octave
mkoctfile: unrecognized argument -arch
make: *** [ov-netcdf.o] Error 1
‘make’ returned the following error: mkoctfile -DHAVE_OCTAVE_ -v -c ov-netcdf.cc -arch i386 -I/Applications/Octave.app/Contents/Resources/include -I/Applications/Octave.app/Contents/Resources/include/curl -I/Applications/Octave.app/Contents/Resources/include/readline -I/Applications/Octave.app/Contents/Resources/include -I/Applications/Octave.app/Contents/Resources/include/curl -I/Applications/Octave.app/Contents/Resources/include/readline -DHAVE_OCTAVE_INT
error: called from `pkg>configure_make’ in file /Applications/Octave.app/Contents/Resources/share/octave/3.2.2/m/pkg/pkg.m near line 1253, column 2
error: called from:
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.2/m/pkg/pkg.m at line 714, column 5
error: /Applications/Octave.app/Contents/Resources/share/octave/3.2.2/m/pkg/pkg.m at line 287, column 7
octave-3.2.2:1>
September 30th, 2009 at 6:04 am
Odd. Why is mkoctfile getting called with -arch? GCC/LD are supposed to be called with those arguments. Is the symlink in /bin the only mod you made to your Octave install?
I’m not sure what to suggest.
October 4th, 2009 at 12:25 pm
It appears to just be that one package. ‘audio’ from octave-forge installs with several warnings but no errors (although without making the fixes above, it also installs without errors, after giving the additional warnings about library architecture).
October 13th, 2009 at 8:33 am
This is a good idea, but putting the stuff there does not get
executed in the case of mex or mkoctfile from within octave.
Instead put
CFLAGS=”-arch i386 ${CFLAGS}”
FFLAGS=”-arch i386 ${FFLAGS}”
CPPFLAGS=”-arch i386 ${CPPFLAGS}”
CXXFLAGS=”-arch i386 ${CXXFLAGS}”
LDFLAGS=”-arch i386 ${LDFLAGS}”
just after
set -e
in mkoctfile-3.2.3 (or whatever) in /Applications/Octave.app/Contents/Resources/bin/
and it fixes it from within octave too!!
October 14th, 2009 at 6:17 pm
Hi guys!
Thank you very much for this trick! It works well, but I have to point out two details:
1) the flag -arch i386 does not work with gcc; AFAIK is an Intel compilers flag. If, like me, you have got gcc, try with -m32:
CFLAGS=”-m32 i386 ${CFLAGS}”
FFLAGS=”-m32 i386 ${FFLAGS}”
CPPFLAGS=”-m32 i386 ${CPPFLAGS}”
CXXFLAGS=”-m32 i386 ${CXXFLAGS}”
LDFLAGS=”-m32 i386 ${LDFLAGS}”
2) in Octave.app one should modify just the /Applications/Octave.app/Contents/Resources/bin/mkoctfile-3.2.3 file, no need to modify mkoctfile. Just paste the code quoted above after set -e. Actually, mkoctave includes mkoctave-3.2.3.
Cheers,
Guido
October 14th, 2009 at 6:30 pm
I am afraid I made a typo. The correct code to paste into mkoctfile-3.2.3 is
CFLAGS=”-m32 ${CFLAGS}”
FFLAGS=”-m32 ${FFLAGS}”
CPPFLAGS=”-m32 ${CPPFLAGS}”
CXXFLAGS=”-m32 ${CXXFLAGS}”
LDFLAGS=”-m32 ${LDFLAGS}”
Sorry!
Cheers,
Guido
October 14th, 2009 at 9:12 pm
Guido,
Did you install a non-Apple build of gcc over the version that comes with the Developer Tools? The -arch flag is supplied by the Apple universal binary framework, not Intel.
October 15th, 2009 at 4:57 am
MacPorts’ Octave works on Snow Leopard for two or three weeks now. You can eben build octave in 64 Bit!
Bye
Sebastian
October 15th, 2009 at 5:45 am
xnk,
thank you for pointing out that. Yes, I installed Gcc 4.5 (experimental) from http://hpc.sourceforge.net/ and it does not accept -arch i386. Intel compilers do, hence I thought it was their peculiarity.
Cheers,
Guido
October 16th, 2009 at 2:27 pm
Hey thanks – this solved the Octave – 10.6 issues for me.
I can confirm that for
– Octave from sourceforge (octave-3.2.3-i386.dmg)
(not from macports, and no changes to gcc)
editing the file
/Applications/Octave.app/Contents/Resource/bin/mkoctfile-3.2.3
and inserting of the form
CFLAGS=”-arch i386 ${CFLAGS}”
fixes mkoctfile and I can now do:
pkg install
for packages from sourceforge.
January 13th, 2010 at 11:43 pm
Thanks a ton. This was quite helpful.