Le forum de XCAS

Xcas: un logiciel libre de calcul formel
Nous sommes actuellement le Jeu Mar 22, 2018 12:36 am

Heures au format UTC

Publier un nouveau sujet Répondre au sujet  [ 6 messages ] 
Auteur Message
 Sujet du message: guide for linking from windows
MessagePublié: Dim Juil 30, 2017 12:17 pm 

Inscrit le: Lun Avr 17, 2017 4:32 pm
Messages: 69
Dear Giac developers,

I have the impression that a selected few have been able to link to the giac library from windows (i.e. first compile the library and the link to it). I have tried doing so in the past and I always seem to fail (I tried cygwin with gcc, visual studio, mingw32 with codeblocks). I think it is wise to ask, before I spend much more time:

1. What would you mostly recommend if I am to compile from windows: mingw (codeblock or not?), gcc (cygwin or not?), visual studio,

2. Once I followed (1) could you please guide me (even if minimally) on linking to the giac library (I assume I need to compile the library.. if this were available pre-compiled, I would be happy enough though!). As much as possible I would like to link dynamically, is this ok?

3. If I get successful I will even go one step ahead and try to make this whole thing work in Visual Studio, as I believe that this is the ultimate goal for any windows developer. But I think I should start one step at a time.

I promise, that once I have gotten this to compile I will write a detailed blog/tutorial for any other person who wishes to compile giac for windows (I haven't seen any so far). For me, giac is very promising because it presents itself as a system that can be compiled and linked from within any operating system and hardware (even those with restricted resources). I therefore would like to support this valuable effort that the developers has put into this computer algebra system. To me it is surprising that giac has not gained as much reputation as it actually deserves (Note: I believe Geogebra uses it and hardly anyone knows that). Since my expertise lies in windows development, I will make sure that this does not go unnoticed in the windows user community. I am trying to convert most of my computer algebra scripts to giac and this has so far worked. If only I could compile C codes with giac under windows I would be overjoyed.


MessagePublié: Lun Juil 31, 2017 9:50 am 

Inscrit le: Mar Déc 20, 2005 4:02 pm
Messages: 4277
Unfortunately I'm not very skillfull in windows development. I can only give you some explanations on how I build a cygwin executable linking to giac and a few hints on visual c++.

A/ building a cygwin exec:
1/ Install cygwin(64), install the required gmp library, install optional libraries (mpfr, mpfi, gsl, ntl, pari, fltk, etc.) either from cygwin or by hand.
To compiling giac.dll, first copy config.h.win64 to config.h in giac-1.2.3/src, adapt it to your local optional libraries installation : for example, if you don't want GUI support, disable fltk, then you won't need uppercase object files (History.o, Cfg.o, etc.). Open Makefile.win64 in src, adapt it to your local optional libraries installation.
Now run make -f Makefile.win64 xcasdll icasdll
This will build giac.dll and xcas/icas, that way you can check that icas or xcas is working before trying your own program.

2/ An example of program:
#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;){
  return a;

int main(){
  cout << "Enter 2 integers ";
  gen a,b;
  cin >> a >> b;
  cout << pgcd(a,b) << endl;
  return 0;

It can be compiled from the src directory with the following commands if all optional libs are installed:
g++ -g -I. -DWIN32 -DHAVE_CONFIG_H -DIN_GIAC -DUSE_OPENGL32 -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS  -c pgcd.cc
g++ -g -I. -DWIN32 -DHAVE_CONFIG_H -DIN_GIAC -DUSE_OPENGL32 -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS  History.o Input.o Xcas1.o Equation.o Print.o Tableur.o Cfg.o Flv_CStyle.o Flve_Check_Button.o Flve_Input.o Flv_Style.o Flv_Data_Source.o Flve_Combo.o Flv_List.o Flv_Table.o Editeur.o Graph.o Graph3d.o Help1.o gl2ps.o pgcd.o -o pgcd giac.dll -mwindows -L/usr/local/lib -lintl.dll -lfltk_images -ljpeg -lfltk -lfltk_gl -lpng -lfltk_forms /usr/lib/libreadline.a /usr/lib/libhistory.a /usr/lib/libncurses.a -lole32 -luuid -lcomctl32 -lwsock32 -lglu32 -lopengl32 -ldmoguids -lgsl -lgslcblas -lintl -lrt -lpthread -llapack -lblas -ldl -lmpfr -lgmp -lintl -lz

./pgcd should run the program, and gdb pgcd.exe debug it (type b pgcd then r then v a to print the variable a of type gen)

B/ VisualC++:
You must first install a GMP-compatible lib (I don't know how GMP is supported, perhaps MPIR would work, or tommath https://www-fourier.ujf-grenoble.fr/~parisse/giac/libtommath.tgz) and will have to make a config.h file and define preprocessor flags, probably:

for tommath, you need to define also USE_GMP_REPLACEMENTS
As I said, I'm not skilled in vc++ development, but perhaps you can ask the geogebra developers how they build their windows version with giac, see the SVN

MessagePublié: Lun Juil 31, 2017 1:50 pm 

Inscrit le: Lun Avr 17, 2017 4:32 pm
Messages: 69
Thanks Bernard. I do remember having had some problems compiling the example (not the library), but I did not install any optional packages back then. Unfortunately I am in a place where internet is extremely unreliable, so installation and download will take a little time. I will be back in Europe next week and will let you know of the outcome ASAP. I will post again at ca. August 9.

Edit: I was able to download giac again. I am opting out of FLTK. I also removed all capital lettered object files from the Makefile OBJS. When gcc tries to compile hist.h (in the xcas rule of the makefile) an error returns that it cannot find FL.h. I suppose I don't really need to test xcas to know if giac is working. So instead I tried to make icas. So in summary:

I did the following in the makefile (called it Makefile.jose):
- instead of just copied config.h.win64 I ran ./configure and then compared config.h.win64 with config.h in the src directory and disabled fltk.
- removed all capital letter objs in "OBJS = " (they are related to GUI and xcas)
- removed pari.o, cocoa.o, Tmpl..., TmpFLG.., from "GIACOBJS="
- removed -lintl.dll, -lfltk_images, -lfltk** (anything fltk related), libreadline.a, libhistory.a, libncurses.a, -ldmoguids, -lgsl, -lgslcblas, -lintl, -lrt, -llapack, -lblas, -ldl, -lmpfr, -lz from LIBS
- execute "make -f Makefile.jose icasdll" from the source directory
I still get errors since:
- sym2poly,gausspol and a lot of other objects requires libintl (do I need libintl for a minimal build of giac?). Can I remove these object files from GIACOBJS?
- maple.cc is being compiled and it also need ntl (how can I disable integration of other computer algebra systems? like maple)
To fix the intl and ntl (there is a typo in the Makefile.win64, -lintl is written twice in "LIBS", I think the author wanted -lintl and -lntl !) I included them in my LIBS (I had them already previously installed so there was nothing to worry).
However maple.cc is still being compiled (can this be opted out?)
In any case, I stopped when I got this (the first error among dozens):
modpoly.o: In function `giac::fft2(int*, int, int, int)':
/usr/src/giac-1.2.3/src/modpoly.cc:7137: undefined reference to `giac::memory_usage()'

Should I disable more options in config.h?

Thank you again! Your advise so far has been very helpful!

MessagePublié: Lun Juil 31, 2017 6:27 pm 

Inscrit le: Mar Déc 20, 2005 4:02 pm
Messages: 4277
Yes, you must probably disable options in config.h. For example if you don't link to libintl, then you must check that HAVE_LIBINTL and HAVE_LIBINTL_DLL are not defined. Then giacintl.h will define gettext as a trivial function returning the C string itself. If you link to libintl, then I think you need two link commands for the lib, one for intl.dll and one for intl (there are 3, one should indeed be removed). I looked at my current configuration and NTL seems to be disabled.
Don't remove pari.o, cocoa.o and Tmp*.o, they are required for linking giac and they will take care of the presence of libpari or libcocoa. maple.o is also required, the filename derives from the fact that some maple compatible commands of Xcas are implemented here.
Don't remove linking to libraries that are installed on your system at first, once you have something working you can remove one lib by one lib and see if it still works.

Good luck!

MessagePublié: Mar Aoû 01, 2017 1:30 pm 

Inscrit le: Lun Avr 17, 2017 4:32 pm
Messages: 69
I gave up on testing giac.dll by compiling icas or xcas, because both will need at a certain point fltk. Disabling fltk will not work the first error that you get is

icas.o: In function `texmacs_graph_output(giac::gen const&, giac::gen&, std::string&, int, giac::context const*)':
/usr/src/giac-1.2.3/src/icas.cc:233: undefined reference to `xcas::fltk_view(giac::gen const&, giac::gen&, std::string const&, std::string&, int, giac::context const*)'
/usr/src/giac-1.2.3/src/icas.cc:233:(.text+0x491): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `xcas::fltk_view(giac::gen const&, giac::gen&, std::string const&, std::string&, int, giac::context const*)'

So I just tried to link to giac.dll (which by the way compiles properly) with pgcd (your suggested example) and had it working. I will see if I can make this work using mingwc and maybe codeblocks (no visual studio yet but at least without cygwin dependency). By the way, if I use giac library can I use pari commands in C++ ? I have been using giacpy (precompiled) for a while and I don't think it has immediate pari support, can I recompile to have pari support in giacpy?

Thanks as always!


MessagePublié: Mar Aoû 01, 2017 2:18 pm 

Inscrit le: Mar Déc 20, 2005 4:02 pm
Messages: 4277
Indeed, the ifdef VISUALC line 159 should be #ifndef HAVE_LIBFLTK

If you have compiled giac.dll with pari, then yes, you should be able to run pari commands in C++ via giac by calling gen _pari(args,GIAC_CONTEXT) (and of course you can also call pari directly from C with type GEN)

Afficher les messages publiés depuis:  Trier par  
Publier un nouveau sujet Répondre au sujet  [ 6 messages ] 

Heures au format UTC

Qui est en ligne ?

Utilisateurs parcourant actuellement ce forum : Aucun utilisateur inscrit et 6 invités

Vous ne pouvez pas publier de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas insérer de pièces jointes dans ce forum

Rechercher pour:
Sauter vers:  
Powered by phpBB® Forum Software © phpBB Group
Traduction réalisée par Maël Soucaze © 2009 phpBB.fr