Importing global variables from a library

kshmirko kshmirko at gmail.com
Tue Sep 28 09:52:35 UTC 2021


On Friday, 10 December 2004 at 10:03:24 UTC, Lionello Lunesu 
wrote:
> Thanks for your advice. It helps if I don't compile the disp.d. 
> I guess it's acting like a C header file now :-/
>
>  > extern(C) {
>> int disp_numrows;
>> int disp_numcols;
>> int disp_cursorrow;
>> int disp_cursorcol;
>> }
>
> I still can't get it to import those 4 integers. I'm starting 
> to think they're simply not available in the library, because 
> in the same disp.d there's a declaration of an extern structure:
>
> // from disp.h: extern disp_t __cdecl disp_state;
> extern (C) disp_t  disp_state;
>
> This one is working and correctly imported. Even if I put it in 
> my compiled module: it doesn't declare a new variable but 
> (correctly) imports it from the C library. However, if I change 
> the name, it doesn't import the variable but declares it.
>
> Lionello.

For your question, just add __gshared attribute
extern __gshared int a, b, c;




More information about the Digitalmars-d mailing list