DMD Stdio Linker Oddities

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 24 12:54:07 PST 2016


On Saturday, 24 December 2016 at 19:58:45 UTC, Jake Pittis wrote:
> I'm posting this in Learn because I'm assuming I've done 
> something wrong rather than discovered a bug.

You need to pass all modules you use to the linker somehow.

Easiest is to `dmd main.d linking_succeeds.d linking_fails.d`

just pass them all to dmd at once.

Alternatively, you can compile all separately with `dmd -c` then 
you link them all with `dmd main.o linking_succeeds.o 
linking_fails.o` or put them in a lib etc.


> In the `linking_fails.d` file, if I replace the stdio import 
> with `import std.algorithm`, running `dmd -main main.d` 
> succeeds. Somehow stdio is causing the linker to fail.

You should pass all at once, but the reason why it sometimes 
works and sometimes doesn't is that std.stdio has a module 
constructor and algorithm doesn't. Since the module constructor 
is there, it becomes a load time dependency and requires the 
module info be present even with nothing else used.


More information about the Digitalmars-d-learn mailing list