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 looks like:

/*-*- compile-command: "/usr/bin/cc -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"; -*-*/

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 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 following are

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

These are install() commands that must be given to GP to let it know about the library. Please read the PARI manual for the meaning of this. The init_squfof function is an initialization function that is created by gp2c to hold code that is outside functions. Since in our case there is 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/examples/squfof.gp.so");
+GP;install("squfof","D0,G,p","squfof_c","./pari/examples/squfof.gp.so");
+GP;install("init_squfof","v","init_squfof_c","./pari/examples/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 2005-01-11