hsc2hs on Mac OS 10.6 unreliable?

Chris Kuklewicz haskell at list.mightyreason.com
Wed Jun 9 04:02:21 EDT 2010

The story on OS X 10.6 with ghc-6.12 on x86 hardware seems to be this:

Apple's gcc: Defaults to i386 or ppc on Mac OS X 10.5 and earlier,
depending on the CPU type detected at runtime. On Mac OS X 10.6 the
default is x86_64 if the CPU supports it, i386 otherwise. Passing -arch
i386 or -arch x86_64 explicitly chooses the mode explicitly.  Passing
BOTH -arch i386 AND -arch x86_64 creates something special which is a
universal binary that holds both versions in a single file.

MacPorts: The provides an easy way to compile and install a plethora of
mostly unix-y software from source.  It handles the arch problem by
allowing +universal to be specified when installing a package or set by
default in /opt/local/etc/macports/variants.conf, which is what I have
done.  Without +universal the default arch can be specified in

gtk: I have build gtk2-2.20.1 with macports as a universal library.

ghc: Unlike ghc on Linux, ghc on OS X is not capable of creating x86_64
libraries and programs.  Using ghc before 6.12 on OS X 10.6 used to
require some small option hacks to explicitly set -arch i386.  Now ghc
is invoked directly. ( http://hackage.haskell.org/trac/ghc/ticket/2965 )

hsc2hs: On OS 10.6 ghc is calling hsc2hs without any special -arch
option, and hsc2hs is calculating offsets in x86_64 mode.  This is
breaking the interface between ghc and c-structures for various
libraries.  In particular I ran into this with gtk2hs.

It may suffice to get '--cc-flag=-m32 --ld-flag=-m32' to hsc2hs as a
work around.  While ticket #2965 is not yet fixed it would be better if
hsc2hs understood the default arch on OS X 10.6 is not compatible with ghc.


On 08/06/2010 22:03, Axel Simon wrote:
> Hi all,
> we're facing serious problems (the seg'faulting kind) with Gtk2Hs on Mac
> OS 10.6. Chris has tracked this down to incorrect structure offsets that
> hsc2hs calculates.
> The offsets that hsc2hs calculates are too large, so it is probably in
> x86_64 mode. The offsets with which Gtk+ was compiled are smaller, so it
> must have been compiled with something like -arch i386. My question is
> the following: What is the right way to compile unixy software on Mac OS
> 10.6. Is the Gtk+ library incorrectly compiled or is hsc2hs not
> producing its C file in the correct way? It seems that a C Gtk+ program
> works correctly when compiled with no special flags.
> The only thing we could do is to pass some magic option to hsc2hs when
> it creates the C program that calculates the offsets. Detecting how Gtk+
> was compiled would require some sort of autoconf magic which is beyond a
> simple cabal file. So I probably cannot hope for an easy fix.
> Any comments or experience appreciated,
> cheers,
> Axel

More information about the Glasgow-haskell-users mailing list