[fpc-pascal] Linking statically C code with stdcall functions

cobines cobines at gmail.com
Fri Mar 5 06:36:12 CET 2010


Hello,

I'm trying to link my program statically with bzip2 library under
Win32. The exported functions are declared as stdcall. I can link
dynamically by declaring functions like this:

function BZ2_bzCompressInit(...): Integer; stdcall; external 'bz2';

It seems that whenever I explicitly give the library name after
'external' FPC always links dynamically, so if I want to link
statically I do:

{$LINKLIB bz2}
function BZ2_bzCompressInit(...): Integer; stdcall; external;

But the names are mangled FPC style:

# nm abbzip2.o | grep -i bzCompressInit
         U ABBZIP2_BZ2_BZCOMPRESSINIT$TBZSTREAMREC$LONGINT$LONGINT$LONGINT$$LONGINT

I found I can do this by specifying names of the functions, but I have
to use mangled names:

{$LINKLIB bz2}
function BZ2_bzCompressInit(...): Integer; stdcall; external name
'_BZ2_bzCompressInit at 16';

Is there a way I can declare the external function to use "C" style mangling?


--
cobines



More information about the fpc-pascal mailing list