Compiling multiple source files --- each file separately, or all together?

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sun Dec 28 22:33:50 UTC 2025


On 29/12/2025 11:14 AM, David Given wrote:
> On Sunday, 28 December 2025 at 21:45:59 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
> [...]
>>> This is beyond my knowledge of D, unfortunately. Is this ever a 
>>> problem in practice?
>>
>> Yes.
> [...]

Attributes are inferred based upon a function body, for functions that 
return by auto, or are within a template.

Attributes, including inferred ones effect mangling of a symbol.

If a symbol name is not exact, you get a linker error.

A .di file does not have its body, so it cannot infer it.

>> Do not ignore import paths.
>>
>> If you are not compiling a module, it MUST come from -I or -extI.
>>
>> It has implications that will result in a binary not linking.
> 
> Can you expand on both, please?

D has required metadata, and in the absence of a flag being set 
internally to the compiler, it assumes it is compiling the module if you 
provide it directly on the command line.

It will emit said metadata, and with that any types, functions, and 
global variables ext. that may exist.

You will get conflicts.

You must tell the compiler that the module has already been compiled, 
and to only import it, not compile it in.

If you are compiling a shared library, the binding (if it refers to a 
module in said shared library), must be noted also as external.

You can either use dllimport set to all, or use -extI and set it to 
externalOnly.

If you do not do this, it cannot see symbols and therefore linker error.


More information about the Digitalmars-d mailing list