source: git/HOWTO-libsingular @ a2dde00

spielwiese
Last change on this file since a2dde00 was 70b4f4, checked in by Hans Schoenemann <hannes@…>, 13 years ago
improved libsingular example git-svn-id: file:///usr/local/Singular/svn/trunk@14235 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.7 KB
Line 
1export CC="gcc -fpic -DPIC -DLIBSINGULAR"
2export CXX="g++ -fpic -DPIC -DLIBSINGULAR"
3
4./configure
5or
6./configure --without-dynamic-kernel
7
8make install-libsingular
9
10---------------------------------------
11how to compile and run the the example:
12g++ -I......include -o tt tt.cc -L..../Singular -lsingular
13export SINGULAR="..../Singular-3-1-3/"
14export SINGULAR_SYSTEM_TYPE="ix86Mac-darwin/lib"
15if [ "${SINGULAR_SYSTEM_TYPE}" = "ix86Mac-darwin/lib" ]; then
16  export
17DYLD_LIBRARY_PATH="${SINGULAR}/${SINGULAR_SYSTEM_TYPE}:${DYLD_LIBRARY_PATH}"
18else
19  export
20LD_LIBRARY_PATH="${SINGULAR}/${SINGULAR_SYSTEM_TYPE}:${LD_LIBRARY_PATH}"
21fi
22unset SINGULAR_SYSTEM_TYPE
23
24./tt
25--------------------------------------
26the example:
27#include <libsingular.h>
28main()
29{
30  // init path names etc.
31  siInit((char *)"/...Singular-3-1-3/Singular/libsingular.so");
32
33  // construct the ring Z/32003[x,y,z]
34  // the variable names
35  char **n=(char**)omalloc(3*sizeof(char*));
36  n[0]=omStrDup("x");
37  n[1]=omStrDup("y");
38  n[2]=omStrDup("z2");
39
40  ring R=rDefault(32003,3,n);
41  // make R the default ring:
42  rChangeCurrRing(R);
43
44  // create the polynomial 1
45  poly p1=p_ISet(1,R);
46
47  // create tthe polynomial 2*x^3*z^2
48  poly p2=p_ISet(2,R);
49  pSetExp(p2,1,3);
50  pSetExp(p2,3,2);
51  pSetm(p2);
52
53  // print p1 + p2
54  pWrite(p1); printf(" + \n"); pWrite(p2); printf("\n");
55
56  // compute p1+p2
57  p1=p_Add_q(p1,p2,R); p2=NULL;
58  pWrite(p1);
59
60  // clean up:
61  pDelete(&p1);
62  rKill(R);
63
64  currentVoice=feInitStdin(NULL);
65  // hook for error handling:
66  // WerrorS_callback=......; of type p(const char *)
67  int err=iiEStart(omStrDup("int ver=system(\"version\");export ver;return();\n"),NULL);
68  if (err) errorreported = 0; // reset error handling
69  printf("interpreter returns %d\n",err);
70  idhdl h=ggetid("ver");
71  if (h!=NULL)
72    printf("singular variable ver of type %d contains %d\n",h->typ,(int)(long)IDDATA(h));
73  else
74    printf("variable ver does not exist\n");
75
76  // calling a singular-library function
77  idhdl datetime=ggetid("datetime");
78  if (datetime==NULL)
79    printf("datetime not found\n");
80  else
81  {
82    leftv res=iiMake_proc(datetime,NULL,NULL);
83    if (res==NULL) { printf("datetime return an error\n"); errorreported = 0; }
84    else           printf("datetime returned type %d, >>%s<<\n",res->Typ(),(char *)res->Data());
85  }
86
87  // calling a kernel function via the interpreter interface
88  sleftv r1; memset(&r1,0,sizeof(r1));
89  sleftv arg; memset(&arg,0,sizeof(r1));
90  arg.rtyp=STRING_CMD;
91  arg.data=omStrDup("huhu");
92  err=iiExprArith1(&r1,&arg,TYPEOF_CMD);
93  printf("interpreter returns %d\n",err);
94  if (err) errorreported = 0; // reset error handling
95  else printf("typeof returned type %d, >>%s<<\n",r1.Typ(),r1.Data());
96  // clean up r1:
97  r1.CleanUp();
98}
Note: See TracBrowser for help on using the repository browser.