Does g++ really need to compile main, if c++ code is involved?

Kilian, Jens Jens.KILIAN@advantest.com
Mon Mar 24 07:14:00 GMT 2014


> From: Florian Weimer [mailto:fw@deneb.enyo.de]
> * Jens Kilian:
> > I remember only one compiler (HP aCC) which requires compiling main()
> > as C++.  As far as I know GCC never needed this.
> 
> Some systems need collect2 support for initializers:
> 
>   <http://gcc.gnu.org/onlinedocs/gccint/Collect2.html>

I interpret this page to mean that GCC will always call the required __main()
from main(), even if compiling C code.  In this case you wouldn't need to
compile main() using g++ (not gcc).

As other posters have pointed out, this is really platform dependent.
There's a comment in 'libgcc/crtstuff.c' which may be relevant:

  Additionally, if the target system supports a .init section,
  this file allows us to support the linking of C++ code
  with a non-C++ main program.

Best regards,

	Jens.



More information about the Gcc-help mailing list