I am having a problem with CGAL from MacPorts on OS X

Created by Harish Narayanan
Keywords:
mac os x macports cgal dolfin

I have just installed dolfin 0.9.7. The build process went smooth via Dorsal. However, I get the following when importing dolfin:

>>> >>>> from dolfin import *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/install_path/bzr/FEniCS/lib/python2.6/site-packages/dolfin/__init__.py", line 13, in <module>
> import dolfin.cpp as cpp
> File "/install_path/bzr/FEniCS/lib/python2.6/site-packages/dolfin/cpp.py", line 28, in <module>
> _cpp = swig_import_helper()
> File "/install_path/bzr/FEniCS/lib/python2.6/site-packages/dolfin/cpp.py", line 24, in swig_import_helper
> _mod = imp.load_module('_cpp', fp, pathname, description)
> ImportError: dlopen(/install_path/bzr/FEniCS/lib/python2.6/site-packages/dolfin/_cpp.so, 2): Library not loaded: /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_gis_cgal/work/CGAL-3.5.1/lib/libCGAL.4.dylib
> Referenced from: /opt/local/lib/libCGAL_Core.4.dylib
> Reason: image not found

This appears to be a bug in MacPorts' CGAL (or perhaps, CMake). In order to get around this for now, you need to do the following strange and dirty trick:

1. Navigate to your MacPorts library folder (/opt/local/lib by default) and do a
   otool -L for each of libCGAL*

2. You will see your strange library
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_gis_cgal/work/CGAL-3.5.1/lib/libCGAL.4.dylib
popup in some of these.

3. Do a
   install_name_tool -change ${brokenlibrary} ${actual_library} file

   for each of the instances in each of the files.

e.g. install_name_tool -change /bigbroken/lib/libCGAL.4.dylib /opt/lib/libCGAL.4.dylib /opt/local/lib/libCGAL_Core.4.dylib