[Issue 16440] wrong code with -main -c -of

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Aug 28 08:09:43 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16440

--- Comment #2 from ag0aep6g at gmail.com ---
(In reply to Andrej Mitrovic from comment #1)
> The problem is the compiler allows -c and -main. It will generate the D main
> function in a separate module but later when you try to link via `dmd
> test.obj` you won't be linking with this module.

I think the module from -main is there when linking, but the one actually given
on the command line is discarded/ignored/overwritten. Otherwise, linking should
fail because of no main. But linking succeeds and produces a program that
doesn't do anything.

[...]
> In the meantime allowing -c and -main in the same invocation should be
> disallowed.

When -of is not given, -c and -main work acceptably together. dmd generates a
__main.o for the main module.

Only with -of do things get weird. I don't see how there would be some
fundamental problem. dmd happily compiles multiple source files to one object
file. So it should be able to add an empty main function to an object file
without breaking the other code.

--


More information about the Digitalmars-d-bugs mailing list