[fpc-pascal] Linking FPC code to a C program

Jonas Maebe jonas.maebe at elis.ugent.be
Mon May 24 14:30:44 CEST 2010


On 24 May 2010, at 13:59, vtech at volny.cz wrote:

> is it possible to link FPC compiled units to a C program on Linux? 
> I'm not able to figure it out.
> FPC uses some strange way to name symbols and whatever I try, I always
> end up with the linking errors.
> I'm probably doing some trivial error, but I just can't find it.
> 
> Simple function:
> 
> function aplusb(a,b:longint):longint;cdecl;
> 
> gets exported as something like: 
> 
> text.n_testunit_aplusb$longint$longint$$longint

Add "export;" at the end of the declaration, then it will also get an unmangled symbol name (but only because it's declared as cdecl). And please do not follow the other advice you got about manually adding an alias, because C name mangling differs from platform to platform and hence the name you'd specify would only work on some platforms.


Jonas


More information about the fpc-pascal mailing list