Problem with coupling shared object symbol visibility with protection

Benjamin Thaut via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 30 10:10:53 PST 2015


Am 30.01.2015 um 11:39 schrieb Martin Nowak:
>
> If you mean float, then it
> will instatiate the template when compiled individually and use b's
> instantiation when b and c are compiled together.

If this is true, then please explain this behavior:

module a; // --> a.dll

struct Storage(T)
{
   T var;
   __gshared T s_var;
}


module b; // --> b.dll
import a;

export __gshared Storage!int g_var1;


module c; // --> c.exe
import a;
import b;

__gshared Storage!int g_var2;

void main(string[] args)
{
   g_var1.var = 2;
   g_var2.var = 3;

   g_var1.s_var = 2;
   g_var2.s_var = 3;
}

c.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol 
"_D1a14__T7StorageTiZ7Storage5s_vari" in Funktion "_Dmain".


If your statement would be true module c should not use the instance 
from module b because they are not compiled together. But as you can 
clearly see from the linker error message module c does not instanciate 
the template, because if module c would instanciate the template there 
would not be a unresolved symbol.

Compiling module c with "-allinst" solves the problem. Putting "export" 
in front of struct Storage(T) also solves the problem. And thats exactly 
the reason why it is neccessary to be able to export templates. (Where 
export means, export all template instanciations)


More information about the Digitalmars-d mailing list