The trials and tribulations of building a simple mesh viewer

Alec Jacobson

February 26, 2010

weblog/

I am beginning a new project and to start I needed to install a peer's CGAL-based mesh viewer. The mesh viewer has many dependencies which in turn have even more dependencies. I will try to recap my struggle and eventual success, here. My warned that this is not an installation guide and is probably missing many things I did and maybe even advertising bad solutions.

64-bit on Mac OS X 10.5

Short story: Don't bother. Long story: My peer has his whole setup all running on 64 bits. This requires building all the dependencies running on 64 bits, which for Mac OS X 10.4 (Leopard) this means compiling everything from source and being really careful about flags. It also means, as far as I know, not using macports. I tried to mimic his compilations and installs but without knowing the exact flags I got almost to the point of having everything working but then my 32-bit installs from macports started really getting in the way. I ended up uninstalling all my macports in vain only to realize that my python(s) were not 64-bit or at least couldn't find 32-bit framework libraries. I recompiled python and pyqt but only found new errors. In the end I gave up on 64-bit (which I'd spent 3 days on) and switched (back) to 32-bit (which only took 1 day).

Dependencies for CGAL using macports

CGAL itself has a macport but it's poorly maintained and will often not compile correctly with your current setup. It seems that a lot of people are having trouble getting this to even build correctly much less work correctly. Instead use macports to install the dependencies then build cgal from source by hand (not so bad). CGAL depends on or supports the following libraries that you don't already have on your mac: Qt3, Qt4 and libqglviewer are only necessary for building the examples and demos which require them and not necessary for the install. Really the only dependency is boost. The rest add more features: exact arithmetic, linear algebra solvers, etc. Those with a *, I'll write more about later on. To install most of the above with macports just issue:
sudo port install boost gmp mpfr zlib
Now, you should be ready to build CGAL.

Installing CGAL

cd to the CGAL directory and issue
cmake -i .
You'll see a prompt for advanced options, I was paranoid so I typed Yes:
Would you like to see advanced options? [No]:Yes
You need to change all library and include directories to point to the macports install directory: /opt/local/lib/WHATEVER or /opt/local/include. For example:
Variable Name: Boost_INCLUDE_DIR
Description: Path to a file.
Current Value: /usr/local/include
New Value (Enter to keep current value): /opt/local/include
Do this for boost, gmp, mpfr etc. Watch out for the CMAKE_INSTALL_PREFIX prompt. If you want CGAL to hang out with your macports then change this to /opt/local like so:
Variable Name: CMAKE_INSTALL_PREFIX
Description: Install path prefix, prepended onto install directories.
Current Value: /usr/local
New Value (Enter to keep current value): /opt/local
In the end, my hackish solution to a later problem prevents all this /opt/local business from mattering but it seems like good practice to have related software in the same place. Unless you feel like macports should be the only one touching /opt/local/ stuff, but it's your computer so why not. Then you can make, sudo make install to finish with CGAL.

Python 2.6 and PyQt4

Simply issue:
sudo port install python26 py26-pyqt4 py26-opengl
sudo python_select python26
These should install fine and work on a simple example. Getting CGAL to recognize your python (and subsequently PyQt) is another problem.

taucs with LU

I was trying to install and unsupported version of the math software taucs. This version had LU decomposition necessary for a feature of the mesh viewer. I ran into trouble forcing the taucs build to see my blas and lapack and to make a proper 32 bit file. After running configure if I tried to run make I would see an error:
build/darwin9.0/makefile:14: config/darwin9.0.mk: No such file or directory
make: *** No rule to make target `config/darwin9.0.mk'.  Stop.
This is because the taucs only cam with a premade make file for darwin, not darwin9.0 as configure has recognized my OS. For the most part you can just copy the darwin make file:
cp config/darwin.mk config/darwin9.0.mk
But make a few changes, namely edit the following lines:
CFLAGS    = -arch i386 -O3 -faltivec
LIBBLAS   = -framework Accelerate
LIBLAPACK = -framework Accelerate
One more thing. The LIBF77 = -Lexternal/lib/darwin -lf2c line is pointing to the right place but the file there is wrong. If you ar -x external/lib/darwin/libf2c.a you'll find out it's full of x86_64 .o files, which will lead to a confused architecture build. My solution was to download the taucs_full from the CGAL download page and copy the libf2c.a on top of this file. Maybe the same is true for the lbmetis.a, I don't remember. Just check that after you make your libtaus.a unarchives to i386 mach-o files. After running make you should move your taucs to the /opt/local area. I just did
sudo mkdir /opt/local/taucs_with_lu
sudo cp -r taucs_with_lu/* /opt/local/taucs_with_lu/.

Hacks

At this point things seemed to work but our meshviewer uses swig to combine cpp code and python. swig was easy enough to install:
sudo port install swig swig-python
But CGAL was not playing nicely. When I built our CGAL meshviewer, CGAL's cmake finders were not locating the libraries I had installed with macports. It kept trying to look in /usr/local/. My hack was to move /usr/local to /usr/local-off and simple link it to /opt/local. Everyone I told this too agreed it was ugly.
sudo mv /usr/local /usr/local-off
sudo ln -s /opt/local /usr/local
This is basically saying, I agree to use macports for everything or I must be very careful. At this point CGAL would play along and build the toy version of our meshviewer. But python would not display it. I think it was because swig would not read the headers from the right place (/opt/local/WHATEVER) instead it was looking in
/Library/Frameworks/Python.Framework/WHATEVER. To handle this I also hacked:
cd /Library/Frameworks/Python.framework/Versions
ln -s /opt/local/Library/Frameworks/Python.framework/Versions/Current Current
cd /Library/Frameworks/Python.framework/
mv Headers Headers-off
ln -s /opt/local/Library/Frameworks/Python.framework/Headers Headers
Again, everyone I told this too said it was a poor man's hack.

CGAL and a deprecated header

Finally, I had everything in order to build the full version of my meshviewer. But I got funny errors about a certain boost header no existing, namely /opt/local/include/boost/property_map.hpp. Upon inspection I noticed that indeed this file does not exist. On my peer's boost install (he did not use macports) he had this file but opening it we saw that it had been long deprecated by boost and simple pointed to the real header in property_map/property_map.hpp one directory lower. I copied my peer's deprecated property_map.hpp and put it in /opt/local/include/boost/ and CGAL found the file correctly. Everything is up and running currently with the exception that my LAPACK is complaining more than my peer's about instantiating primitives correctly. When I solve this (hopefully not with another hack) I will post the results. Hope this helps somebody. Please let me know if you find non-hack solutions to any of these. Update: I think I figured out Blas and Lapack... In my cmake CONFIG.cmake file I have
    SET(CMAKE_CXX_FLAGS "-arch i386")
    SET(CMAKE_C_FLAGS   "-arch i386")
    SET(BLAS_LIBRARIES "/System/Library/Frameworks/Accelerate.framework")
    SET(BLAS_DEFINITIONS "-DBLAS_USE_F2C")
    INCLUDE_DIRECTORIES("/opt/local/include")
    LINK_DIRECTORIES("/opt/local/lib" "lib")
    INCLUDE_DIRECTORIES(/usr/X11/include)
    LINK_DIRECTORIES(/usr/X11/lib)
    SET(TAUCS_INCLUDE_DIR "/opt/local/taucs_with_lu/src/" "/opt/local/taucs_with
    SET(TAUCS_LIBRARIES "/opt/local/taucs_with_lu/lib/darwin9.0/libtaucs.a")
    SET(METIS_LIBRARIES "/opt/local/lib/libmetis.a")
In some files it worked to just above the line where you include the Acceleration framework
#include 
put instead:
#define __LP64__
#include 
For other directories I added this line to the CMakeLists.txt file:
ADD_DEFINITIONS("-D__LP64__")
If I find an elegant way to do this I will repost and update...