April 26, 2004
Wow, this is cool. And i stand corrected. :/ I wonder what made me think the variables exports don't work principally.

-eye

Walter schrieb:

> "Achilleas Margaritis" <axilmar@in.gr> wrote in message
> news:c6gejo$1r7v$1@digitaldaemon.com...
> 
>>Which means that I can't access a C global variable from D; the function
> 
> is
> 
>>accessed ok, but the global variable is not.
>>
>>Is this a bug ? is there some option that I should pass at the compiler ?
>>
>>I am trying to port the Allegro multimedia library to D. Allegro functions
>>work ok, but Allegro global variables can't be accessed.
> 
> 
> The problem is that, in D, a declaration is a definition. So
> 
>     int x;
> 
> will declare and define x. The trick to referencing a C global variable is
> to make a module, let's say foo.d:
> -------------------
> extern (C) int x;
> -------------------
> 
> And then in your code:
> -----------------------
> import foo;
> 
> ... and then refer to foo.x ...
> -----------------------
> 
> but do NOT link in foo.obj. You'll find this trick is used in std.c.stdio to
> refer to _iob[]. stdio.obj is NOT added to phobos.lib, and so the linker
> will look elsewhere for a definition of _iob[].
> 
> 
1 2 3
Next ›   Last »