1 | export CC="gcc -fpic -DPIC -DLIBSINGULAR" |
---|
2 | export CXX="g++ -fpic -DPIC -DLIBSINGULAR" |
---|
3 | |
---|
4 | ./configure |
---|
5 | or |
---|
6 | ./configure --without-dynamic-kernel |
---|
7 | |
---|
8 | make install-libsingular |
---|
9 | |
---|
10 | --------------------------------------- |
---|
11 | how to compile and run the the example: |
---|
12 | g++ -I......include -o tt tt.cc -L..../Singular -lsingular |
---|
13 | export SINGULAR="..../Singular-3-1-3/" |
---|
14 | export SINGULAR_SYSTEM_TYPE="ix86Mac-darwin/lib" |
---|
15 | if [ "${SINGULAR_SYSTEM_TYPE}" = "ix86Mac-darwin/lib" ]; then |
---|
16 | export |
---|
17 | DYLD_LIBRARY_PATH="${SINGULAR}/${SINGULAR_SYSTEM_TYPE}:${DYLD_LIBRARY_PATH}" |
---|
18 | else |
---|
19 | export |
---|
20 | LD_LIBRARY_PATH="${SINGULAR}/${SINGULAR_SYSTEM_TYPE}:${LD_LIBRARY_PATH}" |
---|
21 | fi |
---|
22 | unset SINGULAR_SYSTEM_TYPE |
---|
23 | |
---|
24 | ./tt |
---|
25 | -------------------------------------- |
---|
26 | the example: |
---|
27 | #include <libsingular.h> |
---|
28 | main() |
---|
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=iiAllStart(NULL,"int ver=system(\"version\");\n",BT_proc,0); |
---|
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 | // changing a ring for the interpreter |
---|
88 | // re-using n and R from above |
---|
89 | R=rDefault(32003,3,n); |
---|
90 | idhdl newRingHdl=enterid("R" /* ring name*/, |
---|
91 | 0, /*nesting level, 0=global*/ |
---|
92 | RING_CMD, |
---|
93 | &IDROOT, |
---|
94 | FALSE); |
---|
95 | IDRING(newRingHdl)=R; |
---|
96 | // make R the default ring (include rChangeCurrRing): |
---|
97 | rSetHdl(newRingHdl); |
---|
98 | err=iiAllStart(NULL,"poly p=x;listvar();return();\n"),BT_Proc,0); |
---|
99 | |
---|
100 | // calling a kernel function via the interpreter interface |
---|
101 | sleftv r1; memset(&r1,0,sizeof(r1)); |
---|
102 | sleftv arg; memset(&arg,0,sizeof(r1)); |
---|
103 | arg.rtyp=STRING_CMD; |
---|
104 | arg.data=omStrDup("huhu"); |
---|
105 | err=iiExprArith1(&r1,&arg,TYPEOF_CMD); |
---|
106 | printf("interpreter returns %d\n",err); |
---|
107 | if (err) errorreported = 0; // reset error handling |
---|
108 | else printf("typeof returned type %d, >>%s<<\n",r1.Typ(),r1.Data()); |
---|
109 | // clean up r1: |
---|
110 | r1.CleanUp(); |
---|
111 | } |
---|