Dear GPC Users,
I have pascal code that reads and writes from standard io. I would like to compile it into a library that someone who has only GCC can link to.
With the help of the GPC demo programs, I have arrived at the solution I give below. What is the standard way of solving this problem?
Yours, Kevan Hashemi
----------- My Solution -----------
We arrange our pascal code as a program (as in gcc_c_pas.pas demo):
program example; procedure pascal_procedure; attribute (name='Pascal_Procedure'); begin WriteLn('Here we are in the Pascal Procedure.'); Flush(Output) end; begin end.
We compile this program as a dynamic library:
gpc -o example.o -dynamiclib example.pas --gpc-main=dummy
We can look inside with UNIX command "otool -T -v example.o" and see the _p_initialize routine is there for us to link to. In our C program we have:
extern int _p_initialize (int argc, char **argv, char **envp);
and in the main loop or init routine we put:
_p_initialize (0,NULL,NULL);
Now we link with GCC:
gcc -o lwdaq lwdaq.o example.o
We can call Pascal_Procedure from the C program and get output to the terminal.