[Haskell-cafe] [Haskell] Linker flags for foreign export.
jason.dusek at gmail.com
Wed Mar 9 22:07:25 CET 2011
On Tue, Mar 8, 2011 at 08:23, Max Bolingbroke
<batterseapower at hotmail.com> wrote:
> On 8 March 2011 05:28, Jason Dusek <jason.dusek at gmail.com> wrote:
> > gcc -g -Wall -O2 -fPIC -Wall -o import \
> > -I/usr/lib/ghc-6.12.1/include/ \
> > import.c exports.so
> In my experience, the easiest way to do this is to use gcc to build
> object files from C source files, and then specify those object files
> on the ghc command line in order to get GHC to do the linking step.
> This will deal with linking in the correct RTS and, if you specify
> appropriate -package flags, dependent packages as well.
> If you want a C main function then see user guide section 18.104.22.168 at
Following your advice, I was able to get a working main,
linking the .o's (no attempt at an SO this time) with GHC.
However, what I was hoping to do was build an SO and that
could be linked without GHC, for example via Postgres's
"LANGUAGE C" functionality (load SOs and run them) or Ruby's
DL/Import (same idea for Ruby). Requiring GHC for linking
would really frustrate that goal :)
Is there a tutorial I should be following? Well-Typed's blog
post on this in the early days of shared object support seemed
to be doing what I was doing.
Linux User #510144 | http://counter.li.org/
More information about the Haskell-Cafe