
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. - Nils

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

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
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@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)

On Tue, Dec 11, 2012 at 12:57 PM, Francisco Vieira de Souza
Hi Simon! Is it not necessary to show the type of igraph_bool_t igraphhaskell_initialized like
"int igraph_bool_t igraphhaskell_initialized = 0"?
"igraphhaskell_initialized" is the name of the variable, "igraph_boot_t" is the type of the variable. -- mithrandi, i Ainil en-Balandor, a faer Ambar

On Tue, Dec 11, 2012 at 5:57 AM, Francisco Vieira de Souza < vieira.ufpi@gmail.com> wrote:
Hi Simon! Is it not necessary to show the type of igraph_bool_t igraphhaskell_initialized like
"int igraph_bool_t igraphhaskell_initialized = 0"?
"igraph_bool_t" uses the _t suffix convention for typedefs in C; in other words, it *is* the type. (And if it weren't, that would be a compile time error, not link time.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (5)
-
Brandon Allbery
-
Francisco Vieira de Souza
-
Nils
-
Simon Marlow
-
Tristan Seligmann