Thread overview | |||||
---|---|---|---|---|---|
|
September 17, 2015 Defining compile-time constants? | ||||
---|---|---|---|---|
| ||||
Hi! I am wondering if there is any way to define constants to pass to the compiler like in C (especially useful in combination with Makefiles, for obvious reasons), i.e.: gcc -DPREFIX=\"/usr/local\" -o myprogram main.c Like this a program can look for certain files inside its prefix during runtime and the prefix can be modified for installation in different locations (like /usr, ~/bin, ...) at compile time. But how do I do something like this in D? I am using GDC, but I'd be interested for solutions for DMD as well. Calling standard-library functions at runtime to figure out where the binary is located is okay for my current problem as well, but it's not as flexible as the "define whatever data at compile time and have it available at runtime". Regards, Tim |
September 17, 2015 Re: Defining compile-time constants? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim K. | On 18/09/15 3:32 AM, Tim K. wrote:
> Hi!
>
> I am wondering if there is any way to define constants to pass to the
> compiler like in C (especially useful in combination with Makefiles, for
> obvious reasons), i.e.:
>
> gcc -DPREFIX=\"/usr/local\" -o myprogram main.c
>
> Like this a program can look for certain files inside its prefix during
> runtime and the prefix can be modified for installation in different
> locations (like /usr, ~/bin, ...) at compile time.
>
> But how do I do something like this in D? I am using GDC, but I'd be
> interested for solutions for DMD as well. Calling standard-library
> functions at runtime to figure out where the binary is located is okay
> for my current problem as well, but it's not as flexible as the "define
> whatever data at compile time and have it available at runtime".
>
>
> Regards,
> Tim
Well string imports, could work.
But you would need to save it to a file first.
|
September 17, 2015 Re: Defining compile-time constants? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim K. | On Thursday, 17 September 2015 at 15:32:25 UTC, Tim K. wrote:
> I am wondering if there is any way to define constants to pass to the compiler like in C (especially useful in combination with Makefiles, for obvious reasons), i.e.:
My preference is to make an app.config module that lists these things as variables (or enums) in ordinary D code. Then tell users to edit that file to customize their build. (wp_config.php does this and people are reasonably happy with it. You could even write a little creation app if you wanted to avoid plain editing the file. Like makeconfig PREFIX="/usr/local" and it writes out the config.d file.)
|
Copyright © 1999-2021 by the D Language Foundation