# Compiling Giac in Windows (Cygwin)

I tried many times to compile giac for windows. Giac is a computer algebra system that has the advantage of being very flexibly adaptable to many operating system (if I remember correctly these include: linux, macintosh, WinCE, Android, windows). I believe that the developer(s) (mainly Bernard Parisse) mostly develop for linux. But they made sure that this can be compiled in many other operating systems. They even provided makefiles adapted for different operating systems. As with many other software that claims universal compilability, one needs to still work to get this compiled in an operating system foreign to the developers.

In the past my compilation failed because of some dependencies that I did not understood or because of some flags that I did not set. So after many years, while I was idle in some math conference, I decided to write to the developers and ask their help. Initially I wanted to join their forum, which would allow easier communication between developers and users. It took a while for me to get into their forum. For some reasons, many computer algebra systems seem to have discussion forums that are dormant or very difficult to register. I do remember the same problem when I wanted to register to the Singular forum. After successfully joining the forum, it somehow exhausted me so I did not pursue the question of compiling giac in windows. This was not a wise decision, still after a year I saw the need to compile giac. Switching to linux was a last resort option for me. My developments are so deeply windows rooted that I had to do everything and port to linux and the workload could be much more than trying to find a way to compile giac.

After posting the question in their forum, I was surprised how helpful Bernard was in guiding me. I had three steps in mind if I wanted to have the giac library working in windows:

1. successfully compile in Cygwin
2. successfully compile in Mingw32
3. Successfully compile a library for Visual Studio (2008)

I am glad to announce that I am satisfied with: compiling for cygwin and compiling with mingw32. My next and final goal is to try it in visual studio (which belongs to a separate blog.). I promised Bernard I will document this in a blog because there seems to be a lack of information for early developers using giac (the forum and some old site writes about it, but giac deserves much much more).

To start the walkthrough let me first write that many things (unknown to many people) use giac. Among many others softwares and hardwares the following depends on giac: HP Prime Calculator, TI NSpire calculator, Geogebra. I really believe this boils down to its flexibility playing well in different operating system and environments and its minimal system requirement (which I don’t know what is, but the fact that low spec calculators can work with it is amazing already).

Let us now start with the walkthrough for cygwin. Warning: since this is personalized some filenames in my tutorial uses my initial name (jose) but you can use whatever name you want.

2. Decompress the archive and go to its root directory and run ./configure. This will search installed components and and adjust the config.h in src folder accordingly (make sure you have installed at least gmp in cygwin)
3. Compare the created config.h with config.h.win64 (in src directory) and check if there is anything wrong. For instance, in my case I specifically did not want to have FLTK (even though I had it already installed in cygwin, as this was only xcas related). So I did the following additional changes:
• I removed all the FLTK options in config.h
• I removed all NTL and INTL from the options

Here, by “remove”, I mean I commented them out instead of trying to use #define to 0 because this wouldn’t work (for me). Giac checks predefinitions by #ifdef and not with #if

4. In the source directory copy Makefile.win64 to Makefile.jose and edit Makefile.jose
5. In Makefile.jose:
• remove the capital letter objs in “OBJS = ” (they are related to GUI application, xcas, etc. which is not what I wanted to build. I want to build giac independent on unnecessary libraries)
• remove Tmpl…, TmpFLG… and other capital letter obj files from “GIACOBJS=”
• remove: -lintl.dll, -lintl, -lntl, -ftlk** (anything fltk related), libreadline.a, libhistory.a, libncurses.a, -lgsl, -lgslcblas, -llapack (I did not want to build with blas and lapack).
• I left mpfr (and if you want you can put in libpari, but that will be discussed later) because I found multiprecision floating point kind of necessary. Do not remove gmp! (and if you want leave ntl but I did not experimented with that)
6. Execute
make -f Makefile.jose giac.dll
in src directory

After you have done all this, you can execute a minimal program (Bernard provided me with a minimal program that try giac.dll. Thank you Bernard if you are reading this!). Namely save the following code as jose.cc (I saved in the src directory, but you don’t need to be as dirty as me!):

#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;
}


Now in the same directory (asuming obj files are also there) run:

To compile
g++ -g -I. -DWIN32 -DHAVE_CONFIG_H -DIN_GIAC -DUSE_OPENGL32 -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS -c jose.cc 

To link an create an executable called jose.exe
g++ -g -I. -DWIN32 -DHAVE_CONFIG_H -DIN_GIAC -DUSE_OPENGL32 -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS gl2ps.o jose.o -o jose giac.dll -mwindows -L/usr/local/lib /usr/lib/libreadline.a /usr/lib/libhistory.a /usr/lib/libncurses.a -lole32 -luuid -lcomctl32 -lwsock32 -lglu32 -lopengl32 -ldmoguids -lgsl -lgslcblas -lrt -lpthread -ldl -lmpfr -lgmp -lz 

If things went well you can run the program which computes the gcd of two numbers. Here is the output:

E:\cygwin\usr\src\giac\giac-1.2.3\src\bin\Release>jose
Enter 2 integers 2 3
1

In a next blog I will explain how to compile it independent of cygwin (mingw32). I also will discuss some methods to optimize the output by dynamically linking to standard libraries.