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 -- Maurice Lombardi Laboratoire de Spectrometrie Physique, Universite Joseph Fourier de Grenoble, BP87 38402 Saint Martin d'Heres Cedex FRANCE Tel: 33 (0)4 76 51 47 51 Fax: 33 (0)4 76 51 45 44 mailto:Maurice.Lombardi@ujf-grenoble.fr {$gpc-main=Dummy} Var Testcode: integer; asmname 'testcode'; Procedure p_hello; begin Writeln ('PASCAL says: Hello, world.'); Testcode := TestCode *2; Writeln ('Testcode = ', TestCode); end; Begin { dummy block or else the GNU Pascal compiler will complain and generate a compile error.} End. #include <stdio.h> extern int testcode; C_hello() { printf ("Hello, World - from C \n\r"); testcode = 12; } # Test Makefile for Pascal and C compiler. ..KEEP_STATE: # try2: try_main.o c_hello.o try_hello.o gpc -o try2 try_main.o try_hello.o c_hello.o c_hello.o: c_hello.c gcc -O -c c_hello.c try_hello.o: try_hello.pas gpc -c try_hello.pas try_main.o: try_main.pas gpc -c try_main.pas program Hello (Output); procedure c_hello; external; Procedure p_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.