Scope of import

Mike Parker aldacron at gmail.com
Sat May 15 07:05:00 UTC 2021


On Saturday, 15 May 2021 at 06:55:47 UTC, DLearner wrote:

> 1. Code above compiles but fails on linker step with 'Error 42 
> Symbol Undefined'.
> To me, unexpected behaviour as imports arranged to pick up 
> symbols (with minimum scope).

Your error is a linker error. Imports have nothing to do with the 
linker. They are for the compiler to know which symbols are 
available in the module it's currently compiling. But every 
symbol that you use needs to be linked by the linker, and that's 
a separate step.

>
> 2. Uncommenting the 'import B' in main everything works 
> correctly.

That's odd. What's your command line?

> To me, particularly unexpected behaviour as no symbol from B 
> directly used in main (also undesirable to set scope 
> unnecessarily wide).
>

Whether you use a symbol in main or not is irrelevant to the 
linker. Any symbol accessed anywhere in your program must 
ultimately be linked in.



More information about the Digitalmars-d-learn mailing list