Page 1 sur 1

pgcd.cc and pgcd.cpp

Publié : jeu. mars 14, 2019 9:15 pm
par belanger
First of all, Happy Pi Day.

The French manual has programs pgcd.cc and pgcd.cpp.
I haven't been able to get them to work. It is probably
because my system isn't set up correctly, but I was wondering
if they work for other people. (My computer has enough tools and
libraries to compile giac, but that's probably about it.)

These files are also in the giac distribution, although
the pgcd.cc is different and the pgcd.cpp in the distribution
has the line
#include "pgcd.h"
commented out, which is good since there doesn't seem to be any
file names pgcd.h.

If I compile (either version) of pgcd.cc, it compiles without problem.
(I use the line
g++ -g pgcd.cc -lgiac -lgmp
from the top of the file.) If I try to run it,
./a.out
I get an immediate
Segmentation fault (core dumped)
So there's probably something wonky about my computer.
But if I try to compile pgcd.cpp (with the pgcd.h line commented out) using
g++ -I.. -fPIC -DPIC -g -c pgcd.cpp -o pgcd.lo
from the top of the file, I get errors beginning with
> g++ -I.. -fPIC -DPIC -g -c pgcd.cpp -o pgcd.lo
pgcd.cpp:29:45: error: no matching function for call to ‘giac::una
ry_function_unary::unary_function_unary(giac::gen (*)(const giac::gen&), const string&)’
unary_function_unary __pgcd(&_pgcd,_pgcd_s);
^
(I've attached the full output at the end.)
Does this file compile for anyone else?

Jay

Re: pgcd.cc and pgcd.cpp

Publié : ven. mars 15, 2019 5:26 pm
par parisse
Indeed, the source listing is incomplete, you must add

Code : Tout sélectionner

#include <giac/config.h>
before #include <giac/giac.h>

Re: pgcd.cc and pgcd.cpp

Publié : ven. mars 15, 2019 8:30 pm
par belanger
When I add that line, I still get the same error, starting:
>> g++ -I.. -fPIC -DPIC -g -c pgcd.cpp
pgcd.cpp:30:45: error: no matching function for call to ‘giac::unary_function_unary::unary_function_unary(giac::gen (*)(const giac::gen&), const string&)’
unary_function_unary __pgcd(&_pgcd,_pgcd_s);
^
In file included from /usr/include/giac/giac.h:9,
from pgcd.cpp:7:
/usr/include/giac/unary.h:189:5: note: candidate: ‘giac::unary_function_unary::unary_function_unary(unsigned int, giac::gen (* const&)(const giac::gen&), const giac::partial_derivative*, giac::taylortype, const char*, giac::printfunction, giac::printfunction, giac::printfunction)’

Re: pgcd.cc and pgcd.cpp

Publié : sam. mars 16, 2019 3:50 pm
par parisse
Indeed, it hasn't been updated since a very long time. From doc/en/pgcd.cpp:

Code : Tout sélectionner

// -*- mode:C++ ; compile-command: "g++ -I.. -fPIC -DPIC -g -c pgcd.cpp -o pgcd.lo && ln -sf pgcd.lo pgcd.o && gcc -shared pgcd.lo -lc -lgiac -Wl,-soname -Wl,libpgcd.so.0 -o libpgcd.so.0.0.0 && ln -sf libpgcd.so.0.0.0 libpgcd.so.0 && ln -sf libpgcd.so.0.0.0 libpgcd.so" -*-
using namespace std;
#include <stdexcept>
#include <cmath>
#include <cstdlib>
#include <giac/config.h>
#include <giac/giac.h>
//#include "pgcd.h"

#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC

  gen monpgcd(const gen & a0,const gen & b0){
    gen q,r,a=a0,b=b0;
    for (;b!=0;){
      r=irem(a,b,q);
      a=b;
      b=r;
    }
    return a;
  }
  gen _monpgcd(const gen & args,GIAC_CONTEXT){
    if ( (args.type!=_VECT) || (args._VECTptr->size()!=2))
      setsizeerr();
    vecteur &v=*args._VECTptr;
    return monpgcd(v[0],v[1]);
  }
  const string _monpgcd_s("monpgcd");
  unary_function_eval __monpgcd(0,&_monpgcd,_monpgcd_s);
  unary_function_ptr at_monpgcd (&__monpgcd,0,true);
  

#ifndef NO_NAMESPACE_GIAC
} // namespace giac
#endif // ndef NO_NAMESPACE_GIAC

Re: pgcd.cc and pgcd.cpp

Publié : sam. mars 16, 2019 5:19 pm
par belanger
Thanks! It works perfectly now.

Also, the version of pgcd.cc in that directly both compiles and runs for me.