next up previous
Next: Using gp2c to find Up: A gp2c tutorial Previous: How can I compile


How can I compile directly with gp2c?

Now we want to compile directly with gp2c to understand what happens. We should run the command

./gp2c pari/examples/squfof.gp > squfof.gp.c

This creates a file squfof.gp.c in the gp2c directory. Now read this file with your favorite editor.

The first line is highly system-dependent, but should be similar to:

/*-*- compile-command: "/usr/bin/gcc -c -o pari/examples/squfof.gp.o
  -O3 -Wall -I/usr/local/include pari/examples/squfof.gp.c 
  && /usr/bin/gcc -o pari/examples/squfof.gp.so
  -shared   pari/examples/squfof.gp.o"; -*-*/
This is the command needed to compile this C file to an object file with the C compiler and then to make a shared library with the linker. If you use emacs, typing 'M-x compile' will know about this command, so you will just need to type Return to compile.

The second line is

#include <pari/pari.h>
This includes the PARI header files. It is important that the header files come from the same PARI version as GP, else it will create problems.

The next lines are

/*
GP;install("squfof","D0,G,p","squfof","./pari/examples/squfof.gp.so");
GP;install("init_squfof","v","init_squfof","./pari/.../squfof.gp.so");
*/

The characters "GP;" denote a command that should be read by GP at start-up. Here, the install() commands above must be given to GP to let it know about functions defined by the library.

Please read the entry about the install() command in the PARI manual.

The init_squfof function is an initialization function that is created automatically by gp2c to hold codes that is outside any function. Since in our case there are none, this is a dummy function. In other cases, it is essential. The next lines are

GEN squfof(GEN n, long prec);
void init_squfof(void);
/*End of prototype*/
This is the C prototypes of your functions. The rest of the file is the C code proper.

For teaching purpose, let's run the command

./gp2c -s_c pari/examples/squfof.gp > squfof2.gp.c

and look at the difference between squfof.gp.c and squfof2.gp.c:

diff -u squfof.gp.c squfof2.gp.c

--- squfof.gp.c Tue Feb 26 13:44:42 2002
+++ squfof2.gp.c        Tue Feb 26 13:44:49 2002
@@ -1,8 +1,8 @@
 /*-*- compile-command: "/usr/bin/gcc -c -o pari/examples/squfof.gp.o
  -DMEMSTEP=1048576 -g -Wall -Wno-implicit  -I/usr/local/include
  pari/examples/squfof.gp.c && /usr/bin/ld -o pari/examples/squfof.gp.so
  -shared   pari/examples/squfof.gp.o"; -*-*/
 #include <pari/pari.h>
 /*
-GP;install("squfof","D0,G,p","squfof","./pari/examples/squfof.gp.so");
-GP;install("init_squfof","v","init_squfof","./pari/.../squfof.gp.so");
+GP;install("squfof","D0,G,p","squfof_c","./pari/...les/squfof.gp.so");
+GP;install("init_squfof","v","init_squfof_c","./par.../squfof.gp.so");
 */
 GEN squfof(GEN n, long prec);
 void init_squfof(void);
If you are not familiar with the diff utility, the above mean that only the two lines starting with GP;install have changed. In fact squfof is still named squfof in the C file, but the install command tells GP to rename it squfof_c in the GP session.


next up previous
Next: Using gp2c to find Up: A gp2c tutorial Previous: How can I compile
Bill Allombert 2006-01-28