Forcing my module to be initialized first

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Oct 16 10:23:54 UTC 2023


Okay, after looking at gtkd, I don't think this can be solved with 
module constructors or swapping out to lazy initialization.

One way that might work however is to use a crt_constructor as that runs 
before the D stuff. However it would now hard code your program to your 
system. Over all my suspicion is that there is something wrong with your 
system related to library lookup paths and that should be fixed instead.

```d
void main() {
     import std.stdio;
     import std.process;
     writeln(environment["GTK_BASEPATH"]);
}

pragma(crt_constructor) extern(C) void myEnvironmentVarSetter() {
     import core.sys.posix.stdlib : putenv;
     putenv(cast(char*)"GTK_BASEPATH=~/bin/gtk".ptr);
}
```


More information about the Digitalmars-d-learn mailing list