On Thu, Jul 1, 2010 at 1:13 PM, Paarvai Naai <[email protected]> wrote:
> On Wed, Jun 30, 2010 at 8:59 PM, JonY <[email protected]> wrote:
>> GCC probably recognizes main() so it doesn't mangle it.
>>
>> Adding extern "C" is fine, I usually see it accompanying WinMain/wWinMain
>> and wmain in C++ code, just to be explicit.
>
> Okay, that sounds good for now.
>
And to tell the truth, I don't know what the best way to fix this is.
gcc has hooks to handle main -- for example, ensuring that __main is
called to do constructor initialization, adding an entry point for
potential gcov functionality, and not mangling the name when compiling
under C++.
wmain, unfortunately, is not a standard entry point --- and gcc knows
nothing about it. I looked at the gcc code (albiet quickly) and there
seems to be no way without hacking gcc considerably to make it aware
of the special behavior of wmain.
The linker symbol you are seeing is due to the fact that libmingwex
has an extern "C" wmain entry point that is brought in from the crt
startup entry point during the link phase when -municode is enabled.
We have this wmain in the library so that we can link the call
wWinMain in the user's code. If we didn't have that, obviously, you'd
be seeing "undefined symbol wmain" rather than wWinMain.
I don't know that there's an easy way to alias the 4 possible
functions. I am presuming, of course, that the MS compilers are aware
of these special functions, and always defines them as extern "C"
linkage. Since no headers are required for wmain definitions
themselves, the only workaround at this time is to document that when
compiling with the g++ compiler,
#ifdef __cplusplus
extern "C"
#endif
int wmain(int, wchar_t**, wchar_t**)
{
...
}
Although this brings up yet another reason why we may want to add
"-include _mingw.h" into the c preprocessor via the specs file. We
can make these special declarations in that header file. In addition,
it will allow us to bring in our _mingw_float.h extensions. This can
rid ourselves of the float.h conflict issue as well. This way, we
will always have extern "C" declarations for the 3 special entry
points in addition to the main entry point. The biggest drawback I
see is polluting the namespace, and other potential conflicts.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public