getting __DIR__ and __TIME__ of compilation?

Jacob Carlborg doob at me.com
Fri Dec 27 07:15:20 PST 2013


> Yes, just like what Ali said above,
>
> __FILE__, __DATE__ and __TIME__ do work for their respective usages,
> but I'm also looking for a way to get the current compilation directory
> during compile time, and getcwd() doesn't seem to be working.
>
> Isn't there something like __DIR__ or __PATH__ that I can use to get
> that information?

You can use this ugly hack:

Create a shell script with the following content.

#!/bin/bash
echo `pwd` > dir.txt
dmd main.d -J.

And the D source code:

module main;

enum compilePath = import("dir.txt");
pragma(msg, compilePath);

Run the shell script to compile the D code.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list