[fpc-pascal] Calling function pointer to main program
jonas at freepascal.org
Fri Jan 3 19:35:54 CET 2020
On 03/01/2020 18:33, Ryan Joseph via fpc-pascal wrote:
>> On Jan 2, 2020, at 2:57 PM, Ryan Joseph <genericptr at gmail.com> wrote:
>> extern C_LINKAGE int SDL_main(int argc, char *argv);
>> which they call from within the iOS event loop and that calls the programs main functions which was defined using -XMSDL_main
> I still can't figure out how -XM works. Can anyone provide an example? When ever I try to use it I get linker errors.
> I've basically just started with a trimmed down program that does nothing but define an external new main function (like SDL does). From the SDL sources I thought that it would now point to the main program body but I can't get past linker errors.
> fpc main.pas -XMuser_main
> Undefined symbols for architecture x86_64:
> "_P$TEST_$$_USER_MAIN$LONGINT$PCHAR$$LONGINT", referenced from:
> _PASCALMAIN in main.o
> "_main", referenced from:
> start in crt1.10.5.o
> (maybe you meant: _user_main)
> program test;
> function user_main(argc: cint; argv: pchar): cint; external;
You're missing a "cdecl;" here.
Additionally, you will also have to link in an object/library that does
define a regular "main" function. And note that this will only work on
libc-based targets (afaik only Darwin, Solaris, and AIX at this point).
More information about the fpc-pascal