More than one main

bearophile bearophileHUGS at lycos.com
Thu Mar 24 12:31:32 PDT 2011


Walter:

> rdmd takes command line switches, which you can use to set the version for which 
> main you want.

You are missing the point still, I was talking about a single standard version that works in all cases.
Here is an example. I have a project (program) P, it contains many modules, its main is inside the module M. Among the modules used by P there are the general-purpose modules A, B, C, D. The modules B and C and D contain a main with demo code. The module A imports the module B, and the module D important C and a less commonly useful module E that has no main and no demo. Now I want to compile the program P with a helper, so it has to compile the main contained inside M. I use:
rdmd --build-only M.d
rdmd defined a version named like main_module for just the module M.d, so only its main gets compiled.
Later I want to try the demos inside A, I use:
rdmd A.d
Now main_module is defined only for the module A.d and it's not defined inside the module B that A has required rdmd to compile. So only the main of A.d gets compiled.

If I use a single My_Demo inside every module M, A, B, C, D, and I give:
rdmd -version=My_Demo --build-only M.d
Then all mains are visible and the linker gives the error. Similar things happen if I use this, because both the main of A and B are active:
rdmd -version=My_Demo A.d

If I use a different version for each module, like My_Demo_A inside A.d, My_Demo_B inside B.d, etc, I then later have to compile the code like this:
rdmd -version=My_Demo_M --build-only M.d
rdmd -version=My_Demo_A A.d

This works, but is not as handy as what I have asked.

And I have stressed the word _standard_ because a version like My_Demo_M becomes a convention just of my code, while my point was the usefulness of a standard that's supposed to work with other build tools too, etc, so if I take some D modules from another person I don't later have to use all different version names like:
rdmd -version=My_NiceDemo_foo foo_bar.d
A standard solution avoids this.

Bye,
bearophile


More information about the Digitalmars-d mailing list