I forward this message to the list to enable people to understand the answer which is at the end.
-------- Original Message -------- Objet: RE: Error with asmname Date: Tue, 10 Jul 2001 15:51:51 -0500 De: "Gloria, Jing" j-gloria@ti.com A: "'Maurice Lombardi'" Maurice.Lombardi@ujf-grenoble.fr
Maurice,
pls be kind enough to run my test program in your system and see if it compiles and links correctly. I have attached all three source files and makefile needed. Pls advise which version of GPC you are using.
Thanks in advance for your assistance. I will be making a build of the latest GPC from source tomorrow.
Regards,
Jing Gloria Texas Instruments
---------------------------------------------------------
The problem is with try_hello.pas which is also a main pascal program. The gpc-main trick is only to circumvent the case in which a C module happens to define a function with name identical to the default gpc main name. But you cannot have two gpc mains because you have conflicts with gpc main initializers and finalizers. The solution is to write try_hello.pas as a unit, like this:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
unit try_hello;
INTERFACE
Var Testcode: integer; asmname 'testcode'; Procedure p_hello;
IMPLEMENTATION
Procedure p_hello; begin Writeln ('PASCAL says: Hello, world.'); Testcode := TestCode *2; Writeln ('Testcode = ', TestCode); end;
End.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Your makefile works then.
But this is still not the right way of doing. You do not need makefiles with gpc
Rewrite try_main as
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
program Hello (Output);
uses try_hello;
{$L c_hello.c} procedure c_hello; external;
Begin Writeln ('Starting in main PASCAL module.'); Writeln ('Calling C routine.'); c_hello; Writeln ('Now back from C.'); P_hello; WRITELN ('That is all folks!!') End.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
then you can compile only the main with --automake
gpc try_main.pas -o try_main.exe --automake
gpc automatically compiles try_hello.pas and c_hello.c becauses it has all informations needed in try_main by way of the uses clause for pascal units and {$L } for c modules.
Maurice
BTW I use djgpp/ gpc 20010623 based on gcc 2.95.3