Strange behaviour of rdmd vs. dmd concerning main function

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 9 17:02:16 PST 2017


On Thursday, 9 February 2017 at 16:20:29 UTC, berni wrote:
>> dmd only compiles in the files you actually pass to it. rdmd 
>> will try to find the required files automatically.
>>
>> Since you didn't pass the file with the function to dmd, it 
>> knows it exists, but leaves it out of the final link (it 
>> assumes it might come from a library or something). That's why 
>> you see the error.
>
> Ah ok, I understand. So calling with "dmd Special/special.d 
> Common/common.d" works.
>
> But when I compile common.d to common.o (with dmd -c common.d) 
> and remove common.d after that is there still a possibility to 
> link? The obvious doesn't work:
>
>>$> dmd Special/special.d Common/common.o Special/special.d(4): 
>>Error: module common is in file 'common.d' which cannot be read
>>import path[0] = /usr/include/dmd/phobos
>>import path[1] = /usr/include/dmd/druntime/import

This is not a linker error. It's a compiler error. You need 
common.d for the import, so the compiler can know which symbols 
are available. For any modules you import, you need either the 
original source file (.d) or a D interface (header) file (.di) 
which contains the type & function declarations and any template 
implementations you need.


More information about the Digitalmars-d-learn mailing list