Re: fpc-pascal Digest, Vol 175, Issue 31

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: fpc-pascal Digest, Vol 175, Issue 31

Marcou Gilles
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, [hidden email] a écrit :
>
> Send fpc-pascal mailing list submissions to
> [hidden email]
>
> 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
> [hidden email]
>
> You can reach the person managing the list at
> [hidden email]
>
> 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 <[hidden email]>
> To: [hidden email]
> Subject: [fpc-pascal] trying to use C code in .pas on WIN32
> Message-ID: <[hidden email]>
> 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  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
> ------------------------------
>
> End of fpc-pascal Digest, Vol 175, Issue 31
> *******************************************

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal