[Haskell-cafe] GHCi + FFI + global C variables

Francisco Vieira de Souza vieira.ufpi at gmail.com
Tue Dec 11 11:57:30 CET 2012


Hi Simon! Is it not necessary to show the type of igraph_bool_t
igraphhaskell_initialized like

"int igraph_bool_t igraphhaskell_initialized = 0"?

Success!
Vieira

2012/12/11 Simon Marlow <marlowsd at gmail.com>:
> On 10/12/12 00:11, Nils wrote:
>>
>> 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",
>> igraphhaskell_initialized);
>>         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.
>
>
> Sounds like it could be this: http://hackage.haskell.org/trac/ghc/ticket/781
>
> Compiling your program with -fPIC should fix it.
>
> Cheers,
>         Simon
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



-- 
"Embora ninguém possa voltar atrás e fazer um novo começo, qualquer um
pode começar agora e fazer um novo fim". (Chico Xavier)



More information about the Haskell-Cafe mailing list