[Haskell-beginners] Problems linking code from the book Haskell School of Expression

Philippe Sismondi psismondi at arqux.com
Fri Nov 25 18:16:19 CET 2011

Greetings. Yesterday I decided to try some of the code in Paul Hudak's book The Haskell School of Expression. I am having problems when I do ghc --make of the code on page 40 of the book, which is the first graphics program therein.

I am running OS X Snow Leopard, with the Haskell Platform (32 bit), ghc version 7.0.3. I am very green when it comes to looking under the covers at what gcc, ld, etc do at the behest of ghc. This is where things seem to go wrong, as I outline below.

In setting up to try this code I discovered that I needed to install the package soegtk to get Graphics.SOE.Gtk. The cabal install of soegtk was not smooth: it appears to me that cabal does not always handle dependencies as one would hope. However, I eventually got soegtk and the packages upon which it depends installed. Here is my list of local user packages as reported by ghc-pkg:


Oddly, in the course of running cabal install to get the above packages, at some point I got a flurry of messages similar to the one below. (This is not one of the actual messages from cabal install; I did not keep those. This warning message is from the ghc --make step, as described below.)

ld: warning: ignoring file /opt/local/lib/libgtk-x11-2.0.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

This puzzled me, and the same thing came up at a later stage, as I shall describe shortly. But initially I ignored the messages and proceeded to try to make my sample program. Here is the code from Hudak's book, which I put in Main.hs:

module Main where

import Graphics.SOE.Gtk

main =
    runGraphics (
    do w <- openWindow "SOE First Try" (300,300)
       drawInWindow w (text (100,100) "Hello Graphics World")
       k <- getKey w
       closeWindow w
When I do ghc --make Main, it grinds forever at the link stage. The link fails. It also gives ld warnings about ignoring libraries in /opt/local/lib, as in the example above. 

Then, the link eventually fails because of a huge number of unresolved symbols. Here is a sample link error from the verbose output:

Undefined symbols for architecture i386:
  "_cairo_arc", referenced from:
      _sbnE_info in libHSsoegtk-0.12.1.a(Gtk.o)
      _se2n_info in libHSsoegtk-0.12.1.a(Gtk.o)
      _sf5B_info in libHSsoegtk-0.12.1.a(Gtk.o)
      _svSr_info in libHScairo-0.12.2.a(Paths.o)
      _swiH_info in libHScairo-0.12.2.a(Paths.o)
  "_cairo_arc_negative", referenced from:
      _seqb_info in libHSsoegtk-0.12.1.a(Gtk.o)
      _svPR_info in libHScairo-0.12.2.a(Paths.o)
      _swg7_info in libHScairo-0.12.2.a(Paths.o)

and on and on.

I have no idea what is happening here.

First, I don't know whether the linker messages about ignoring libs in /opt/local/lib is connected with the unresolved symbols, but one would suspect that it is.

Second, it is not clear to me why ghc would link against anything in /opt/local/lib, which it clearly does. Here are the first couple of lines of verbose output from ghc --make, showing the inclusion of the flag -L/opt/local/lib:

/Developer/usr/bin/gcc -v -o Main -march=i686 -m32 -fno-stack-protector -DDONT_WANT_WIN32_DLL_SUPPORT Main.o -L/Users/Philippe/Library/Haskell/ghc-7.0.3/lib/soegtk-0.12.1/lib -L/Library/Haskell/ghc-7.0.3/lib/stm- -L/Users/Philippe/Library/Haskell/ghc-7.0.3/lib/gtk-0.12.2/lib -L/opt/local/lib -L/Users/Philippe/Library/Haskell/ghc-7.0.3/lib/pango-0.12.2/lib 

I have plenty of macports stuff installed in /opt/local. But I have not intentionally included /opt/local/lib in any path. That is, I do NOT have, for example, LD_LIBRARY_PATH or DYLD_LIBRARY_PATH set. 

So is it normal for ghc to link against /opt/local/lib libraries, or is it something in my environment that is triggering this?

And, in any case, is that why the link fails? What about the references to "architecture i386"? Do they provide the necessary clue for the clueless (me)?

Any help is appreciated.

- Phil -

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111125/38282355/attachment.htm>

More information about the Beginners mailing list