Wednesday, November 08, 2006

CERNLIB, ddd, case conflict, ppc binaries, DYLD_LIBRARY_PATH

While installing CERNLIB I ran into problems with the currently-available g77 and gfortran for Intel OS X. CERNLIB is a set of libraries and utilities including PAW and PAW++, tools for analyzing data from particle physics experiments. CERNLIB makes heavy use of special features of g77, and although it can be compiled with gfortran on Intel Macs (after applying Keisuke Fujii's patches), the resulting binaries have run-time errors that make them unusable. (CERNLIB developers are aware of this problem.) The unofficial g77 port to Intel OS X can't build working binaries either.

The runtime errors are thrown by CERNLIB's ZEBRA system for managing dynamic data structures under Fortran 77 (!). For reference, the error messages look something like this:

!!!!! ZFATAL called from MZIOCH
called from MZFORM

!!!!! ZFATAL reached from MZIOCH for Case= 1

IQUEST(11) = ********* 52494448 HDIR
IQUEST(12) = 0 0
IQUEST(13) = 5 5

In an attempt to isolate theproblem, I installed the excellent debugger, DDD. I installed from source, putting the executable into my /local directory tree.

While installing DDD, I ran into a conflict between the "case philosophies" of Linux and OS X. OS X is "case preserving", meaning that it will display the case of characters in file names, but internally it doesn't care whether the file is named "JoEBob.dAt" or "joebob.dat". Linux is truly "case sensitive", and distinguishes between files whose names only differ in case.

Some X applications will make use of application-specific X resources files (called app-defaults files). These files are typically named after the X application's "class", which is usually the same as the application name, but capitalized. While installing DDD, I found that the newly-created binary ("ddd") was overwriting the app-defaults file ("Ddd") which was stored in the same directory. I fixed the problem by moving the binary and re-making the app-defaults file.

Watching an errant CERNLIB program run with DDD led me deep into the guts of ZEBRA, but didn't provide any obvious solution to the problem. So I decided to fall back to the pre-compiled PowerPC binaries for CERNLIB. These are available in the Fink repository as "cernlib2005*.deb". In order to install these with dpkg, I had to append the flag "--force-architecture", since the debs were compiled for PowerPC rather than Intel.

After installing the package, an attempt to run pawX11 resulted in:

# pawX11
dyld: Library not loaded: /usr/X11R6/lib/libX11.6.dylib
Referenced from: /sw/bin/pawX11
Reason: no suitable image found. Did find:
/usr/X11R6/lib/libX11.6.dylib: mach-o, but wrong architecture
Trace/BPT trap

This was because the installed X11 libraries (from fink's xorg packages) were for Intel. To get around this, I fetched the PowerPC version of the xorg-shlibs deb. Rather than installing the package, I then extracted the contents of this deb into a directory, using "dpkg-deb --extract", then put the files into a convenient location ("/common/lib/ppc") that could be shared among all of the Macs I'll be managing. Finally, I set the DYLD_LIBRARY_PATH environment variable to point to this directory. This causes OS X's dynamic linker ("dyld", which is equivalent to Linux's "ld.so") to search first for dynamic libraries in /common/lib/ppc, before it goes on to search its default path. After these changes, pawX11 runs properly. In order to make paw++ work, I had to fetch the openmotif3-shlibs package for PowerPC and extract its contents into the same directory.

No comments: