digitalmars.D.learn - Defining compile-time constants?
- Tim K. (16/16) Sep 17 2015 Hi!
- Rikki Cattermole (3/18) Sep 17 2015 Well string imports, could work.
- Adam D. Ruppe (8/11) Sep 17 2015 My preference is to make an app.config module that lists these
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
Sep 17 2015
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, TimWell string imports, could work. But you would need to save it to a file first.
Sep 17 2015
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.)
Sep 17 2015