dgdc

GDC equivalent to dmd's -main option


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?


Solution

  • 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.