[fpc-pascal] fpc-pascal Digest, Vol 175, Issue 31

MARCOU Gilles g.marcou at unistra.fr
Thu Jan 24 14:29:41 CET 2019


Hi,

I am not sure that I can help, but this is an interesting topic and I am curious if you find a solution.

I can only assume that maybe you did not link to gcc and c libraries. Inside Common.pas, you should try to add {$link c} and {$link gcc}. You may check also that the symbol of your function looks as you assume it is. Use the command ’nm’ on Cygwin. On DOS you can also use vcvarsall.bat or dumpbin.exe.

Ciao,
Gilles Marcou

> Le 24 janv. 2019 à 12:00, fpc-pascal-request at lists.freepascal.org a écrit :
> 
> Send fpc-pascal mailing list submissions to
> 	fpc-pascal at lists.freepascal.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> or, via email, send a message with subject or body 'help' to
> 	fpc-pascal-request at lists.freepascal.org
> 
> You can reach the person managing the list at
> 	fpc-pascal-owner at lists.freepascal.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of fpc-pascal digest..."
> 
> 
> Today's Topics:
> 
>   1.  trying to use C code in .pas on WIN32 (conlin664)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Wed, 23 Jan 2019 14:30:38 -0700 (MST)
> From: conlin664 <conlin664 at yahoo.com>
> To: fpc-pascal at lists.freepascal.org
> Subject: [fpc-pascal] trying to use C code in .pas on WIN32
> Message-ID: <1548279038991-0.post at n5.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> 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.
> 
> 
> the a CommonTest.pp file:
> 
> Program commonTest;
> uses
> Common;
> 
> begin
>  writeln('got here');
>  CutilInit();
> end.
> 
> 
> fpc.exe -TWin32 -Mdelphi -vw -Sg  -Ci -O1 -Cp386 -XS -gl -p- -b-
> 
> is the relevant way I'm invoking fpc
> 
> It links, but then does nothing on execution.
> 
> If I change the C line to be:
> 
> procedure CutilInit;  cdecl; external;
> 
> I think get a link error
> Undefined Symbol: _CutilInit
> 
> Any ideas ?
> 
> Does the linklib define need to be below where I declare the C routines ?
> Is it something to do with WINDOWS.. ( aka the _ in the name )
> 
> Maybe I need different options on the C compile..
> 
> 
> 
> 
> 
> 
> --
> Sent from: http://free-pascal-general.1045716.n5.nabble.com/
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> 
> ------------------------------
> 
> End of fpc-pascal Digest, Vol 175, Issue 31
> *******************************************




More information about the fpc-pascal mailing list