# GHC Undefined

michael vorin mivori at hotmail.com
Wed Dec 11 17:13:53 EST 2002

```Whilst I was trying to get the curses binding example in QForeign to compile
- I stumbled on what I believe to be a bug. Essentialy I believe that the
version of ld.exe that you have packaged up with ghc 5.04 win32 has a bug or
is perhaps badly configured.

ghc uses - GNU ld version 2.11.90 (20010704) (with BFD 2.11.90)

which did not properly resolve external references to variables (see below).

I resolved problem by using - GNU ld version 2.13, from current mingw
release.

my configuration
GHC 5.04 Win32 running on win2K platform.
What I encountered
--------------------
ghc -fglasgow-exts CursesTest.hs CursesTest_hsc.c Curses.hs curses_hsc.c
-lpdcurses

curses_hsc.o(.text+0x4):curses_hsc.c: undefined reference to `stdscr'
curses_hsc.o(.text+0x10):curses_hsc.c: undefined reference to `LINES'
curses_hsc.o(.text+0x1c):curses_hsc.c: undefined reference to `COLS'
curses_hsc.o(.text+0x28):curses_hsc.c: undefined reference to `COLOR_PAIRS'
curses_hsc.o(.text+0x34):curses_hsc.c: undefined reference to `COLORS'

when I had a look at the object files and the libpdcurses.dll, the
appropriate symbols were in fact defined, and in fact all functions were
resolved, the above symbols represent bindings to variables declared as
follows:-

extern	int	LINES;

2. setup of a test
-----------------
I setup a test (test.c attached) where I just had one external reference
that I was trying to resolve. I compiled it

curses\tst-lines>ghc tst.c -o tst.exe -lpdcurses
tst.o(.text+0x4):tst.c: undefined reference to `LINES'

curses\tst-lines>gcc tst.c -o tst.exe -lpdcurses
Info: resolving _LINES by linking to __imp__LINES (auto-import)

the above should give the same result, i.e. the later result

3. fix
--------
I copied ld.exe from my mingw release (version 2.13) over ld.exe in the ghc
release (version 2.11.90 ). This solved my problem

4. postmortem
-------------
why the problem ? Does this problem occur with all external variable
references or is limitted to a few dll libraries, does it occur linking
against static libraries ?

I don't know

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail
-------------- next part --------------
#include "curses.h"
#include <stdlib.h>

extern	int	LINES;

int *hs_lines (void) {return &LINES;}

int main()
{

return 0;
}

```