How to compile and link simple application?

Julian julian.fondren at gmail.com
Mon Apr 8 20:12:28 UTC 2019


On Monday, 8 April 2019 at 19:43:11 UTC, Julian wrote:
> On Monday, 8 April 2019 at 19:29:33 UTC, 4544fa8d wrote:
>> It's really not possible to call functions in modules like in 
>> any other languages? :S
>
> What some other languages do is collect all of those calls into 
> an
> implicit function that's called before main(). What D does is 
> run
> that code at compile-time.

Another way, from https://dlang.org/spec/module.html#staticorder

In thisexe.d:

   import std.stdio, std.path, std.file;

   public string root_dir;

   shared static this() {
       root_dir = dirName(thisExePath());
   }

In thisexe_ex.d:

   #! /usr/bin/env rdmd
   import thisexe, std.stdio;

   void main() {
       writeln(root_dir);
   }

does what you'd expect.


More information about the Digitalmars-d-learn mailing list