[fpc-pascal] trying to use C code in .pas on WIN32
Sven Barth
pascaldragon at googlemail.com
Fri Jan 25 07:56:39 CET 2019
Am Fr., 25. Jan. 2019, 01:01 hat Marc Santhoff <M.Santhoff at web.de>
geschrieben:
> On Wed, 2019-01-23 at 14:30 -0700, conlin664 via fpc-pascal wrote:
> > I've done research, but am just missing something.
> > my .pas code links just fine, but doesn't RUN.
> > ( first writeln never appears )
> > If I remove the external call to C code, then the writeln works as
> normal.
> >
> > Problem:
> >
> > I have c code, which I'm compiling on a WIN32 machine ( yes the horror )
> > using GCC 4.5.2 target mingw32
> >
> > It generates .o files which i grouped together with ar into common.a
> > I then renamed common.a to be libcommon.a
> >
> > Then I have a
> >
> > Common.pas file:
> >
> > unit Common;
> > interface
> >
> > uses
> > sysutils, dos, CTypes;
> >
> > {$linklib libcommon.a }
> >
> > procedure CutilInit; cdecl; external 'CutilInit';
> >
> > implementation
> >
> > end.
> >
>
> Try stdcall on Win32:
>
> procedure CutilInit; stdcall; external 'common' name 'CutilInit';
>
> If the full external declaration is necessary you'll have to try. I had to
> when using a dynamic library (.dll in win32 terms).
>
The "external LIB name FUNC" is wrong in the case of static linking as is
"external FUNC" as the poster wrote, cause that is in fact "external LIB".
So instead try "external name FUNC" (though I didn't test it). Using the
correct calling convention still applies of course.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190125/b2c6453b/attachment.html>
More information about the fpc-pascal
mailing list