DIP45: fixing the dllimport/dllexport issue

Benjamin Thaut code at benjamin-thaut.de
Sat Sep 7 05:47:20 PDT 2013


Ok there is a new problem. Consider the following example:

module lib1;

export int lib1Func()
{
   return 5;
}


module lib2;
import lib1;

export int lib2Func()
{
   return lib1Func() + 1;
}


If you compile lib1 into a static library and then copmpile lib2 into a 
DLL which statically links against lib1 both symbols lib1Func and 
lib2Func will be exported from the dll because lib1Func will get marked 
as dllexport when compiled into a static library and the static library 
transports that information into the linking process of lib2. This 
happens both on win32 and win64. But this is something you really don't 
want. Lets imagine you have a DLL that statically links against phobos. 
Suddenly you will have all phobos exported symbols in your dll. This can 
also lead to double defined symbols in case a user links against your 
dll and against the shared phobos dll. So we have to fix this somehow.

I propose that we add a command-line-paramter to the compiler (windows 
only) which actually enables dllexport. So all behavior described in the 
DIP will be enabled by default, but to actually make it mark symbols 
with dllexport you have to specifiy a additional command-line-parameter. 
We could call it "-dll" or something.

In case you want to try it out yourself, here is the repro case: 
http://stuff.benjamin-thaut.de/D/dll2.zip

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d mailing list