I like dlang but i don't like dub

Mike Parker aldacron at gmail.com
Tue Mar 22 15:20:18 UTC 2022


On Tuesday, 22 March 2022 at 14:44:59 UTC, Marcone wrote:
> Why is dmd unable to import modules installed by dub using the 
> import command like it does with the Phobos library? He can't 
> send these modules to Linker? Needing to be passed to dmd via 
> command line. I think it could be all automatic.

`import` itself has nothing to do with the linker, and it is not 
the reason Phobos is automatically linked. That happens because 
the compiler *always* passes Phobos to the linker, whether you 
import anything from it or not (though not in BetterC).

When you import a module from a library, the compiler is only 
using the import to understand which symbols are available to the 
module it's currently compiling. It does not attempt to compile 
the imported modules and doesn't have enough information to pass 
anything to the linker. It has no idea if an imported module is 
already compiled, or will be compiled later, and whether it will 
be passed to the linker as an object file or part of a static 
library, or if it won't go to the linker at all because it's in a 
dynamic library.

The only time `import` has any impact on the linker is when you 
pass `-i` to the compiler, in which case it will attempt to 
compile the modules it imports (excluding Phobos) and, in turn, 
pass the compiled object to the linker. But that's going to 
compile everything every time.

Because the compiler supports separate compilation and linking, 
it can't make any assumptions about what you actually want to 
compile and link. That's what build tools like dub and reggae are 
for.


More information about the Digitalmars-d-learn mailing list