24 January 2022

Developing Giac with Qt Creator on Windows

Giac Is A CAS, that's why the abbreviation. But seriously: Giac is indeed a CAS (Computer Algebra System), and it's used by millions of people. Especially among those who use GeoGebra, because GeoGebra includes an embedded version of Giac.

Giac is developed by the French mathematician and (in its best meaning) hacker Bernard Parisse, a researcher of Institut Fourier in Grenoble, France. Giac has been more or less a one-person-project for several years – Bernard fights against bugs more or less alone. This is, of course, very dangerous if long-term goals are planned, because it would be rather difficult to replace him.

During the last years a couple of young programmers at GeoGebra joined the work a bit, at least in fighting against various platforms and compilers. To name just a few, Zbyněk Konečný, Balázs Bencze and Ágoston Sütő worked quite a lot on this field. But debugging and resolving issues remained a battle for the old-fashioned hackers like Bernard – using Emacs on a Unix-like platform. No Windows, no graphical debugging, just the command line with some support from Emacs. You know Emacs? I guess you don't. People say: Love it or leave it. It's something for an older generation of programmers.

A couple of years ago I put some effort to sketch up the required steps to import Giac's source code in CLion. I used it a couple of times, but finally I moved towards another tool, Qt Creator, because it was free. That was OK for me, but I still felt that I am mostly alone with this solution. After some years now I finally found the way how to move on to make it work also in Windows. This blog entry is about this new method.

OK, so how to debug Giac on Windows?

From this point on I will be very technical.

First you need to install MSYS2. We will use the CLANG64 flavor to compile Giac, via cmake. I assume you already know how to set everything up and use the pacman package manager to install the following packages:


The next step is to start Qt Creator. You will find it in the folder C:\tools\msys64\bin\ as qtcreator.exe. On startup you may get a couple of error messages, but you can safely ignore them. Now open File > New File or Project… and select Projects > Import Project > Git Clone > Choose…:


The following step is to import Giac's repository. At the moment you will need my fork of the official GeoGebra repository for the Giac development, because Qt Creator will use cmake to set up the build system, and the required settings are not yet present in the official version. So please clone my repository https://github.com/kovzol/giac-1 as follows:



Now a challenging step is to be performed. We need to select a well-working toolchain (a.k.a. kit) – in my case there were a lot of toolchains already installed, but the matching one is something like Desktop Qt (shared) MinGW-w64 CLANG64 (MSYS2). Eventually you may have multiple kits with the same name (as in my case):


Now scroll down and press Configure project. This will implicitly start cmake and hopefully the kit will be initialized properly for Giac.

Before building Giac we should set that we need a terminal application. So let's go to the Projects tab on the left part of the window, click on Build & Run > Desktop Qt (shared) MinGW-w64 CLANG64 (MSYS2) > Run, and then check the box Run > Run in terminal:


On the right part of the window you will see some feedback from cmake if the configuration went well. But now we are ready to start Giac in a terminal by clicking on the button on the left part of the window.

A request to run Giac will implicitly start a new build. This may take a couple of minutes if you have a slow computer. Otherwise a black window appears soon and you can enter an example input, e.g. 1+2 or expand((a+b)^2). Don't forget to press ENTER. If you are happy with the output, press Ctrl-C and close the terminal window.

OK, Giac runs now as a terminal application, but how to debug it?

That's the point! Click Edit on the left part of the window and select some files from Giac's source code from the file hierarchy:


It is useful to set Tools > Options > C++ > Code Style to GNU. This will change the default tab size to 8 and the indent size to 2 – these settings are the correct ones for Giac's source code.

Now you will be able to set some breakpoints in the code:


And then you can start debugging by using the icon below the the button (it actually shows a play button with a picture of a bug). After this step the terminal application is launching again, but for this time in debug mode. This means that the breakpoints we set will be enabled.


Here I set a second breakpoint in vecteur.cc, line 4382, to learn what happens if I enter the commands caseval("init geogebra") and a:={ggbvect[1,2,3]}*identity(3) consecutively:


Then, on the next stop at the second breakpoint I am able to look into the fine detail:


Some variables may have values that are difficult to read without some hacks. For example, by adding a user expression to evaluate can tell some more detail on the contents of the current variables:


Here I used ainf.dbgprint() to read the content of the giac::gen type variable ainf. Of course, this little secret was only revealed to me by Bernard a couple of weeks ago.

OK, enough said, stop reading and start hacking!


Entries on topic technical developments

  1. Embedding realgeom in GeoGebra (9 July 2021)
  2. Web version of Tarski (1 October 2021)
  3. Developing Giac with Qt Creator on Windows (24 January 2022)
  4. Compiling Giac via MSYS2/CLANG32 (2 April 2022)
  5. Terminals on the web (28 June 2022)
  6. Torus puzzle (15 April 2023)
  7. Tube amoeba (16 April 2023)
  8. XaoS in WebAssembly (30 August 2023)
  9. Debut of GNU Aris in WebAssembly (11 November 2023)
  10. JGEX 0.81 (in Hungarian) (10 December 2023)
  11. xaos.app (2 January 2024)
  12. Compiling and running bibref-qt on Wine (22 August 2024)

Zoltán Kovács
Linz School of Education
Johannes Kepler University
Altenberger Strasse 69
A-4040 Linz