To use giac inside of a C++ program, put
| #include <giac/giac.h> |
at the beginning of the file. To compile the file, use
| c++ -g progname.cc -lgiac -lgmp |
After compiling, there will be a file a.out which can be run with the command
| ./a.out |
As an example, put the following program in a file named pgcd.cc.
| #include <giac/config.h> #include <giac/giac.h> using namespace std; using namespace giac; gen pgcd(gen a,gen b) { gen q,r; for (;b!=0;) { r=irem(a,b,q); a=b; b=r; } return a; } int main() { cout << "Enter 2 integers "; gen a,b; cin >> a >> b; cout << pgcd(a,b) << endl; return 0; } |
After compiling this with
| c++ -g pgcd.cc -lgiac -lgmp |
and running it with
| ./a.out |
a prompt will appear:
| Enter 2 integers |
After entering two integers, such as
| Enter 2 integers 30 36 |
the result will appear:
| 6 |