OPTLINK needs to die.

Walter Bright newshound1 at digitalmars.com
Mon Feb 16 22:19:47 PST 2009


Tom S wrote:
> I've tried it before and unfortunately there's a problem with this 
> approach: static ctors from modules linked from a .lib don't get executed:

Not everything is linked in from a library, just referenced things 
(that's the whole point of a library). There is nothing referenced in 
mod.d. But rewriting as:

---------------
import mod;

void main()
{
     foo();
}
---------------
import std.c.stdio;

void foo() { }

static this() {
         printf("Running a static ctor for Mod"\n);
}
---------------

Compiling and running:

C:>dmd -lib mod

C:>dmd test5 mod.lib

C:>test5
Running a static ctor for Mod


Or, compile the module with just the static constructor in it separately 
and add it explicitly to the link list.



More information about the Digitalmars-d mailing list