lanceboyle@qwest.net wrote:
Sorry for the Ada content herein but I have to cross-bother *someone*. 8^)
I'm trying to get a simple Ada program to access simple Pascal code--see bottom of this post. (I also want to call Ada code from Pascal, but I haven't tried that yet.)
I've read "6.11.2 Exporting GPC Libraries to Other Languages" from the GPC docs and "2.10.1 Interfacing to C" in the GNAT docs.
I _think_ that I can prepare the Pascal code and call it from Ada assuming C calling conventions; at least, that's what I'm trying.
The command lines that I am using, with the working directory the one containing all the source files, are:
gpc -c mypascalunit.pas -o mypascalunit.o gnatmake adacallspascal.adb -largs mypascalunit.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/ libgpc.a
By the way, to make this more generic, you can replace
/Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/libgpc.a
with
`gpc -print-file-name=libgpc.a`
with quotes and all. Also, the symbolic link /Developer/Pascal/gpclibs points to the directory that contains libgpc.a.
(the gnatmake command is all one line)
This causes the following output (sorry if there are any impolite line breaks):
gcc -c adacallspascal.adb gnatbind -x adacallspascal.ali gnatlink mypascalunit.o /Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/ libgpc.a adacallspascal.ali ld: Undefined symbols: _frommypascalunit gnatlink: cannot call /usr/bin/gcc gnatmake: *** link failed.
I'm linking libgpc.a because I think that is the GPC runtime library and prevents complaints about undefined symbols such as __p_Write_String.
Question: Why doesn't the linker see _frommypascalunit???
Because of the default linker name of Pascal procedures (see below). To view the symbol names in mypascalunit.o, use the 'nm' utility.
Here are the two programs, Ada main and Pascal unit.
with Ada.Text_IO; use Ada.Text_IO; procedure adacallspascal is
procedure frommypascalunit; pragma Import(C, Frommypascalunit);
begin Put_Line("Hello from adacallspascal."); frommypascalunit; end adacallspascal;
unit mypascalunit; interface procedure frommypascalunit; implementation procedure frommypascalunit; begin writeln('Hello from frommypascalunit.'); end; end.
Try
unit mypascalunit; interface procedure frommypascalunit; attribute( name = 'frommypascalunit'); implementation procedure frommypascalunit; begin writeln('Hello from frommypascalunit.'); end; end.
Thanks for any comments at all. I've never tried anything like this.
Remember to initialize the Pascal runtime lib, see e.g. /Developer/Pascal/gpc344d2/doc/gpc/demos/gpc_c_c.c.
It would be interesting to add Ada support to gp (and to the GPC Xcode Kit on Mac OS X), but then we have another situtation, namely calling Ada from a Pascal program.
Regards,
Adriaan van Os