How to set constant value to environment variable at compile time?

Narxa fbf99eQrXpHcjP8L at gmail.com
Mon Dec 10 11:08:23 UTC 2018


Hello, people!

I would like to have a constant with the value of some 
environment variable that is defined at compile time.

In FreePascal, it can be done by defining it in source as:

VALUE_OF_SOMETHING = {$I %SOMETHING%};

And I can call the compiler with (bash):

SOMETHING='Anything' export SOMETHING; <compiler> <flags>

And it will automatically assign VALUE_OF_SOMETHING to 'Anything'.


In GCC C compiler, the solution I found was more complicated but 
it worked.

I had to explicitly define the environment variable when calling 
the compiler with:

gcc <flags> -DSOMETHING=\""Anything"\" -o <output> <source_file>


Now, I would like to do that with the 'dmd' compiler.

I know I could possibly use 'gdc' to achieve that but I want to 
use the 'dmd' compiler.

Is it possible to do that such a thing or through source or any 
other means?


Thank you!


More information about the Digitalmars-d-learn mailing list