Dynamic linking again

Simon Marlow simonmar@microsoft.com
Mon, 2 Sep 2002 11:31:27 +0100

> So here's another idea. ghc's linker provides (via the ffi) a command
> addDLL to load dynamic libraries. It uses dlopen on unix and=20
> LoadLibrary on win32.=20
> Now, with dlopen if you pass it NULL rather than the filename of a
> library it will give you back a handle to itself - the program that
> called it. If you've linked your program with the right incantations
> this gives you access to all the symbols in the main program.

Yes, we already use dlopen() with NULL to get symbols from other shared
libraries, so you can refer to things like printf() from libc.

I didn't know about -export-dynamic: yes, it looks like that would do
exactly the right thing.  The linker might not even need any
modification for this to work, because we already fall back to using
dlsym() for a symbol that the linker can't find in its own symbol table.

[... I've just tried a simple example using -export-dynamic, and it does
indeed work as advertised... ]

To like the whole of the base package into the binary, you can either
use --whole-archive with libHSbase.a as suggested by Alastair, or link
in HSbase.o.  Similarly for the haskell98 package.

Let us know how you get on...