Forcing my module to be initialized first

dan dan.hitt at gmail.com
Mon Oct 16 03:31:13 UTC 2023


I have some code that i would like executed before anything else 
is.

The code is to set an environment variable which is used by a 
library.  I'm trying to find some way to avoid setting the 
environment variable on the command line, or in any shell script 
or initialization file.

I think the place to put such code would be in a 'static this' 
inside a module.

So i need some way to force my module to be initialized first, 
ahead of all others.

I suppose if i could figure out a way to make all other modules 
depend on my module this would happen, but the module which uses 
the variable i want to set is in some already-compiled dynamic 
library that i would prefer not to touch.

Alternatively, is there some entry point besides main that i 
could use, that executes before main and before any module 
initialization is done? (Is it possible to get in before the d 
runtime starts?)  Although i would prefer to code in d, it would 
be ok to do it in c.

This is on MacOS (Catalina) in case that makes a difference, and 
i'm using dmd v2.104.0.

Thanks in advance for any clues.

dan


More information about the Digitalmars-d-learn mailing list