[Haskell-cafe] Undefined symbol error coming from shared, dynamic library.

Sergiy Nazarenko nazarenko.sergiy at gmail.com
Wed Sep 14 18:14:35 CEST 2011

Hi, Captain !
I got haskell shared libraries with following cabal command:

cabal install --global --reinstall --disable-library-profiling
--enable-shared  --ghc-option=-dynamic mtl
and so on.

It allowed me to get haskell libraries and I could compile my own
shared libraries. And ldd helps me to know which libraries need me to
use them on users computers with my library. I believe this cabal
options can set in ~/.cabal/config or somethisg like this. In my case
I merely create shell script and call it cabal-shared.sh. :)

There is my options to compile my library:

ghc -O2 --make -no-hs-main -dynamic -shared -fPIC -optl '-shared'
-optc '-DMODULE=MyLibModule' -o MyLibModule.so MyLibModule.hs
module_init.c -optl-Wl -lHSrts-ghc7.0.2

where module_init.c has contents:

#define CAT(a,b) XCAT(a,b)
#define XCAT(a,b) a ## b
#define STR(a) XSTR(a)
#define XSTR(a) #a

#include <HsFFI.h>

extern void CAT (__stginit_, MODULE) (void);

static void library_init (void) __attribute__ ((constructor));
static void library_init (void)
  /* This seems to be a no-op, but it makes the GHCRTS envvar work. */
  static char *argv[] = { STR (MODULE) ".so", 0 }, **argv_ = argv;
  static int argc = 1;

  hs_init (&argc, &argv_);
  hs_add_root (CAT (__stginit_, MODULE));

static void library_exit (void) __attribute__ ((destructor));
static void library_exit (void) {  hs_exit (); }


More information about the Haskell-Cafe mailing list