How to get compiler name and version from D code?

Iain Buclaw ibuclaw at gdcproject.org
Fri Jul 29 10:10:26 UTC 2022


On Friday, 29 July 2022 at 09:57:43 UTC, Dennis wrote:
> On Friday, 29 July 2022 at 09:29:47 UTC, Kirill wrote:
>> ```
>> Built with COMPILER_NAME COMPILER_VERSION
>> ```
>
> Something like this:
> ```D
> version(DigitalMars) enum compiler = "DMD";
> else version(LDC)    enum compiler = "LDC";
> else version(GNU)    enum compiler = "GDC";
> else enum compiler = "Unknown compiler";
>
> enum buildInfo = "Built with "~compiler~" 
> "~__VERSION__.stringof;
>
> pragma(msg, buildInfo); // "Built with DMD 2099L"
> ```
> With a bit more effort you could format the version nicely as 
> "2.099".

Or just `import std.compiler;`

https://dlang.org/phobos/std_compiler.html


More information about the Digitalmars-d mailing list