Re: [AD] Magic main in Windows |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Mon, Aug 02, 2004, Evert Glebbeek wrote:
> Interesting. How widely supported is this? From the look and general
> usefulness, I'd suspect it to be a GNU extension. If both GCC and MSVC
> support this, that would be great.
They both do. The only one I had problems with was Borland's (but I
only have version 6; maybe people who own more recent versions might
check that).
By the way, I have used the previously mentioned #define for the
Debian version of Allegro, to avoid the necessity for alleg_unsharable.a
which was breaking prelinking (because of undefines weak symbols).
To maintain compatibility with binaries linked with classic Allegro
versions, (which don't contain a main() routine) I have added the
following code to src/unix/umain.c:
/* main:
* Replacement for main function (capture arguments and call real main).
*/
int main(int argc, char *argv[]) {
int (*real_main) (int, char*[]);
void **_mangled_main_address;
char *program = argv[0] ? argv[0] : "program";
fprintf(stderr, "%s: built with a non-Debian Allegro, running glue code\n",
program);
_mangled_main_address = dlsym(NULL, "_mangled_main_address");
if(_mangled_main_address == NULL) {
fprintf(stderr, "%s: mangled main address not found\n", program);
return -1;
}
real_main = (int (*) (int, char*[])) *_mangled_main_address;
__crt0_argc = argc;
__crt0_argv = argv;
fprintf(stderr, "%s: everything went fine\n", program);
return (*real_main)(argc, argv);
}
--
Sam.