modules and mains
Brian Tiffin
btiffin at gnu.org
Sun Aug 22 03:46:46 UTC 2021
On Sunday, 22 August 2021 at 03:22:02 UTC, Brian Tiffin wrote:
> Is this wrong thinking? I'm ~~working on~~ playing with a
> first project.
>
> Meant to be a suite of tools, each usable from the command
> line, i.e. with a `main`. Then a manager program that accepts
> subcommands for dispatch *and other boss type things*.
>
> boss.d wants to import command1.d command2.d etc.
>
> Is there a way for `command1.d` to know it's an `import` versus
> a file named as part of a `gdc` compile?
>
> I'd like to skip defining `main` during `import` (using a
> different name for boss dispatch), but do define `main` when
> it's a standalone compile. Or is that a bad way of thinking
> about D program development interactions?
>
> Cheers
Tried this:
```d
prompt$ cat A.d
module A;
version (boss) {} else {
int main(string[] args) {
return command(args);
}
}
int command(string[] args) {
import std.stdio: writeln;
writeln(args);
return 0;
}
```
with
```d
prompt$ cat B.d
module B;
version = boss;
import A;
int main(string[] args) {
A.command(["Boss calling A"]);
return 0;
}
```
But I'm getting a link error from gdc
```
prompt$ gdc -o B B.d
/tmp/ccWg1BrF.o: In function `_Dmain':
B.d:(.text+0x52): undefined reference to `_D1A7commandFAAyaZi'
collect2: error: ld returned 1 exit status
```
Is it just wrong thinking and *try again, ya noob*? ;-)
Cheers again
More information about the Digitalmars-d-learn
mailing list