GDC equivalent to dmd's -main option

108 Views Asked by At

Does the GNU D Compiler provide a flag similar to the -main flag of dmd? I've checked the options list for both GCC itself and gdmd (designed to take similar arguments to dmd, but use gdc instead), and couldn't find anything like it.

If such a flag exists, what can I do to get similar behaviour?

2

There are 2 best solutions below

0
On BEST ANSWER

You could create a module that contains a main function guarded by a version block.

version(emitMain) void main() {} 

If you would normally use '-main', now use '-version=emitMain'. This way your build system does not have to take care of not including this module for your normal builds that already have a main function.

0
On

GDMD does contain a -main argument. What version are you using?
From GDMD D Compiler 2.068 using gdc (Gentoo 8.1.0 p1.2) 8.1.0:

Usage:
  ...
  -main        add default main() (e.g for unittesting)

It works on my machine, and it should too on yours. Please use an updated GDMD.