modules and mains
Ali Çehreli
acehreli at yahoo.com
Sun Aug 22 04:38:58 UTC 2021
On 8/21/21 8:46 PM, Brian Tiffin wrote:
> prompt$ cat B.d
> module B;
> version = boss;
A cannot know about 'version' condition inside B.
The solution is to provide version on the command line. This is how I do
it with dmd:
$ dmd -version=boss [...]
(So, remove 'version = boss;' line in B.d)
> 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*? ;-)
Never! :)
D modules work both like C's .h files and .c files. (Well, more like
C++'s .h files because templates don't need .cpp part.) We import for
declarations but we must also include for linking. Again, this is how it
works with dmd:
$ dmd B.d A.d -version=boss
Another option is to use dmd's -i switch, which automatically includes
modules for linking but I don't have experience with it other than it works:
$ dmd B.d -version=boss -i
(-i can take a pattern as well.)
Ali
More information about the Digitalmars-d-learn
mailing list