Re: [AD] Preparing for 4.9.9

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Tue, 2009-03-10 at 10:30 -0700, Evert Glebbeek wrote:
> On 10 mrt 2009, at 10:22, Elias Pschernig wrote:
> > However, some testing with the mingw cross-compiler reveals that it is
> > only working under Windows with static linking. With SHARED enabled in
> > cmake, gcc complains about not finding al_main while creating the DLL.
> 
> I thought the point was that we wanted the magic main to be in a  
> static library anyway?

Yeah, so it wouldn't be a big problem.

> Besides (as I said), there is a patch (on the mailing list somewhere)  
> that makes it possible to use main() instead of WinMain() on Windows.  
> IIRC, no special code is needed for MinGW, and MSVC requires a #pragma.

Ahh, very nice then. It's independent from the above though. We simply
can call the function "main" instead of "WinMain" then if someone with
Windows can get it to work reliably.

> > Also, the trick to allow "int main(void)" does not work for C++ as the
> > prototype has to be declared with extern "C", and C++ does not allow
> > inexact prototypes as C does.
> 
> Ah, maybe C++ was the reason. But I'm not sure I understand: we simply  
> #define main al_main, then have the "extern void al_main(int, char  
> **);" in our own (C) source file - so the C++ compiler would not see  
> this at all?
> (I didn't look at your attached patch to verify any of this).

In C++, the function has to be declared as extern "C" - or it would be a
C++ function. Therefore the patch has this:

#define main al_main
#ifdef __cplusplus
   extern "C" int al_main(int argc, char **argv);
#endif

But that makes the prototype for C++ programs fixed. I.e. in your code
now you can only use this:

int main(int argc, char **argv) {...}

What would work is leaving out the #ifdef above and do this in your
code:

extern "C" int main() {...}
extern "C" int main(int argc, char **argv) {...}

I.e. both will work again now, but you have to add the extern "C"
yourself.

-- 
Elias Pschernig <elias@xxxxxxxxxx>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/