Compiling multiple source files --- each file separately, or all together?
monkyyy
crazymonkyyy at gmail.com
Fri Dec 26 14:33:48 UTC 2025
On Friday, 26 December 2025 at 10:44:21 UTC, David Given wrote:
> When compiling C or C++, and you have multiple source files,
> you typically compile each source file independently into a .o
> file and then link them together. This is either done manually
> in the build script or automatically if you pass multiple
> source files into the compiler program.
>
> When compiling D, and I do this:
>
> ldmd2 a.d b.d c.d d.d -o program
>
> ...it's unclear to me whether it's doing the same as C/C++
> does, and compiling each file individually, or whether it's
> compiling all the .d files together using a single compiler
> instance. I _think_ it's compiling them together (and then
> invoking the linker as its own stage). Can anyone confirm/deny
> this? If it's true, is this true for all dmd-like D compilers?
>
> Context: working on D support for a build tool, and it makes a
> big difference to how my tooling would work.
>
> Thanks!
the d compiler will group files together as much as possible, and
if you try to do 1970's c and break each compilation step apart
youll break templates
Hottake, d doesnt need its current crop of build tools and from
your command your treating it like a c compiler. Its not the
1970's, theres is no header files; consider just assuming
something simpler will work and doing the simple thing.
More information about the Digitalmars-d
mailing list