dlang-tour / core

D Language online tour (https://tour.dlang.org/) and online editor (https://run.dlang.io/)
Boost Software License 1.0
119 stars 48 forks source link

run.dlang.io: multiple modules sometimes cause linking errors #755

Open pbackus opened 4 years ago

pbackus commented 4 years ago

This example compiles and runs:

--- bar.d
module bar;

--- main.d
module main;
void main() {}

This one doesn't:

--- bar.d
module bar;

--- foo.d
module foo;

--- main.d
module main;
void main() {}

...with the following error:

/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

In both cases, the compiler is set to dmd and no compiler arguments are given.

Passing -run main.d as compiler arguments allows the second example to compile and run successfully.