Hello,
i want to migrate a C project to Lazarus and want to keep the tested backend functions, so i created a minimal project to test calling C functions from Pascal. The structure is like this:
Prepare C interface module:
cstub.c and cstub.h => hpas -cd cstub.h => cstub.pp
gcc -c -m32 cstub.c => cstub.o
Prepare Pascal interface module pstub.pas and include linker options:
{$link cstub.o}
{$linklib libgcc.a}
Add all of this to the project.
When cstub.c is self contained and does not use any libc functions the project compiles, links and runs as expected.
When cstub.c contains calls to strlen() or strcpy() i get this "undefined symbol" linker error. Strangely enough this error occurs only when compiling on Windows. The same construct compiles, links and runs fine on Linux.
In both cases i used the current versions of Lazarus and gcc available. On Windows i used mingw.
I tried:
- I checked with "strings ...". The symbol _strlen is contained in libgcc.a (which is no surprise) and cstub.o
- When i change the linklib option to a wrong name like "libgccX.a" i get the expected "no such file" linker error.
So it looks to me the linker does load libgcc.a but for some reason cannot match the _strlen contained in cstub.o to the _strlen contained in libgcc.a
Did anyone encounter the same or a similar problem? Any ideas what i did miss?
Best regards, Bruno