GHCi + FFI + global C variables

Nils mail at
Mon Dec 10 01:11:30 CET 2012

I'm currently working with a C library that needs to use/modify global C 
variables, for example:

    igraph_bool_t igraphhaskell_initialized = 0;

    int igraphhaskell_initialize()
      if (igraphhaskell_initialized != 0)
        printf("C: Not initializing. igraphhaskell_initialized = %i\n", 
        return 1;
      // initialization

If I compile an example programm using this library everything works 
fine, but if I try to run the same program in GHCi it dies with the message

    C: Not initializing. igraphhaskell_initialized = -907777

The value (and apparently the adress of the global variable) is 
completly off, and I have no idea what is causing this or how to solve 
this issue and make the library GHCi-friendly. Is it possible to run 
this code in GHCi at all? Also, since it's a foreign library I obviously 
cannot just change the C code to simply not use any global variables at all.

- Nils

More information about the Glasgow-haskell-users mailing list