Compiling multiple source files --- each file separately, or all together?
H. S. Teoh
hsteoh at qfbox.info
Sun Dec 28 00:34:35 UTC 2025
On Sat, Dec 27, 2025 at 09:33:56PM +0000, David Given via Digitalmars-d wrote:
[...]
> One thing which looks like it'll complicate matters is the handling of
> `.di` files. AFAICT the compiler needs to see them in specific places
> so that it can find them, so that the `.di` file for the package
> `foo.bar.baz` needs to be in `foo/bar/baz.di` relative to the search
> path. But when they're written with `-H`, the prefix directories
> aren't written automatically, so I need `-Hd=$(OBJ)/foo/bar` or the
> equivalent --- i.e. the build system needs to know the package path of
> the file it's compiling.
[...]
What's the reason you're generating .di files? Those are only necessary
when you need to link with binary-only 3rd party libraries. Where the
source code is available, it is preferable to compile against the
sources instead of .di files. D is not C++; you do not need "header
files" to import library modules. Just specify the include paths to the
library source code and import away.
The compiler is able to do more analysis and optimizations when the
target library source is available. Declarations imported via .di files
are subject to some limitations. Furthermore, modern, idiomatic D often
uses templates extensively, and templates interact poorly with .di
files.
T
--
An elephant: A mouse built to government specifications. -- Robert Heinlein
More information about the Digitalmars-d
mailing list