Markus Gerwinski wrote:
Frank Heckenbach wrote:
a) You must link the Pascal object file:
gcc footest.c foo.o -o footest
I did so, getting another error message. (See parallel mail)
As other have pointed out, you also have to link the RTS (either explicitly `-lgpc -lm' or by using gpc for linking).
b) You must init the RTS etc. (if the Pascal code uses any of it which most Pascal code does), see the demo programs gpc_c_pas.pas and gpc_c_unit.pas.
Does this example mean, I have to write a pascal _program_ file just to ignore its "main"?!
No, this is just an example. You can also have just units/modules (and generally, this seems preferable). As the main program says:
WriteLn ('This is never called.');
So it does not intialize the RTS.
Isn't there a more explicit way to init the RTS?
The example C code does un-/initialize the RTS explicitly (_p_initialize/_p_finalize), as well as the Pascal unit and program init_pascal_main_program ().
If you have just units, you have to call init_Foo () (where Foo is the name of the unit) for each unit, except those which are used by other units (since their intializer is called by the other unit one's), but it doesn't hurt to call an initializer multiple times.
So I recommend to either call the initializer of all units, or to have a "top level" unit which uses all other ones, and call its intializer from C.
c) You should specify the asmname of the Pascal routine: procedure bar; asmname 'Bar';
(Currently, this is the default used by GPC, but this will change soon as a preparationn for qualified identifiers, and you probably don't want your code to break then.)
Certainly not... Did you already plot the new default rule GPC will use after the change? --
No, and I don't think we'll publish an "official" default naming so that ...
In fact, this means I'll _have_ to give every variable, routine etc. an asmname in order to keep my code gcc-compatible, right?
Yes. (Each one you use from C, of course.)
Frank