[fpc-pascal] Linking C object against "Pascal runtime"

Jonas Maebe jonas.maebe at elis.ugent.be
Sun May 9 00:11:53 CEST 2010


On 08 May 2010, at 21:37, moichos at gmx.de wrote:

> I have a C file which I want to link statically into my FreePascal application. The C code is mostly self-contained, except for a few simple calls to the C runtime, one of them being "_strlen".
> 
> Now "_strlen" is a simple enough function to rewrite it in Pascal, and so I did. However, FreePascal seems unable to recognize my strlen function in Pascal. It keeps reporting "Error: Undefined symbol: _strlen". My code looks like this, and "_strlen" is clearly present:

C name mangling is not the same on all systems. On several systems, if you declare a function called "strlen" in C, the assembler symbol will actually be called "_strlen". The C compiler automatically adds the "_" prefix if necessary, and so does FPC when you use the "cdecl" calling convention. So change the "_strlen" into "strlen" and try again.


Jonas


More information about the fpc-pascal mailing list