This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Does g++ really need to compile main, if c++ code is involved?
- From: Eric Wolf <eric dot wolf at abas dot de>
- To: "Kilian, Jens" <Jens dot KILIAN at advantest dot com>
- Cc: Florian Weimer <fw at deneb dot enyo dot de>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 24 Mar 2014 08:13:57 +0100
- Subject: Re: Does g++ really need to compile main, if c++ code is involved?
- Authentication-results: sourceware.org; auth=none
- References: <87d2hc8z3f dot fsf at mid dot deneb dot enyo dot de> <a9400063c32f4c658723d4cdb23f157b at BN1PR05MB262 dot namprd05 dot prod dot outlook dot com>
Am 03/24/2014 08:04 AM, schrieb Kilian, Jens:
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).
But that's strange. With this little example:
----- test.cpp ----------
#include <iostream>
class A {
public:
int a;
A() { a = 5; }
void showA() { std::cout << a << std::endl; }
};
A a;
int main(int argc, char * argv[]) {
a.showA();
return 0;
}
----- test.cpp ----------
and doing
g++ -static -O0 -o test test.cpp
nm test | grep main
no __main pops up.
Could be inlined though?
But there is a
__libc_start_main
symbol, maybe __main got renamed?
Yours sincerely,
Eric Wolf