简体   繁体   中英

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM