Dear GPC Users,
I have installed gpc on my MacOS 10.2.6 computer. I have the following makefile, which makes executable glue out of main.c and foobar.p. I compile main.c as a library so I can look inside it with otool -v -t -V and see the symbolic stub references.
glue: main.o foobar.o gpc main.o foobar.o -o glue
main.o: main.c gpc -c main.c -o main.o
foobar.o: foobar.p gpc -c foobar.p -o foobar.o rm foobar.p
clean: rm foobar.o foobar_unit.gpi main.o glue
Foobar.p looks like:
unit Foobar_Unit;
interface
function Foobar(x:longint):longint;
implementation
function Foobar(x:longint):longint; begin Foobar:=x*x*x; end;
end.
and main.c looks like:
#include <stdio.h> extern int Foobar(int x); int main() { printf("The Foobar of %d is %d \n",5,Foobar(5)); return 0; }
I get no compiler warnings, but when I run glue from the terminal command line my output is:
The Foobar of 5 is -1985538999
I have been trying for a couple of days, and I cannot get the main.o object to link correctly to foobar.o. I think I need to add some gpc command-line options, but none that I have tried seem to work. Thy symbols in the objects are correct, and I get an unresolved symbol error if I remove foobar.o from the makefile directory.
Can you help?
Yours, Kevan Hashemi, Brandeis University Physics Department
Kevan Hashemi wrote:
I get no compiler warnings, but when I run glue from the terminal command line my output is:
The Foobar of 5 is -1985538999
You are using "int" in C and "longint" in Pascal. "Int" in C and "integer" in Pascal are both 4-byte on Mac OS X, where "longint" is 8-byte on Mac OS X. See <www.microbizz.nl/gpcdiffs.html> and section 6.2.3.2 of gpc.pdf.
Regards,
Adriaan van Os
Kevan Hashemi wrote:
I have installed gpc on my MacOS 10.2.6 computer. I have the following makefile, which makes executable glue out of main.c and foobar.p.function Foobar(x:longint):longint;
A further note. Issues regarding linking Pascal and C in general are demonstrated in gpc_c_pas.pas and c_gpc.pas in the demos folder (probably /Developer/Pascal/gpc33d6/doc/gpc/demos).
Regards,
Adriaan van Os