0

I am learning CUDD package for research purposes. I have got one sample code from which I have tried to learn the basic functionalities. But I am getting error during compilation.

I have already set the paths for the header.

#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include "cudd.h"
#include "util.h"

void print_dd(DdManager *gbm, DdNode *dd, int n, int pr)
{
    printf("Ddmanager nodes : %ld \n",Cudd_ReadNodeCount(gbm)); 
    printf("Ddmanager vars : %d \n",Cudd_ReadSize(gbm)); 
    printf("Ddmanager reorderings :%d\n",Cudd_ReadReorderings(gbm));
    printf("DdManager memory % ld",Cudd_ReadMemoryInUse(gbm));
    Cudd_PrintDebug(gbm,dd,n,pr);
}

void write_dd(DdManager *gbm, DdNode *dd, char * filename)
{
   FILE *outfile; 
   outfile=fopen(filename,"w");
   DdNode **ddnodearray=(DdNode **)malloc(sizeof(DdNode*));
   ddnodearray[0]=dd;
   Cudd_DumpDot(gbm,1,ddnodearray,NULL,NULL,outfile);
   free(ddnodearray);
   fclose(outfile);
}

int main(int argc, char *argv[])
{
    DdManager *gbm;
    char filename[30];
    gbm=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
    DdNode *bdd=Cudd_bddNewVar(gbm);
    Cudd_Ref(bdd);
    bdd=Cudd_BddToAdd(gbm,bdd);
    print_dd(gbm,bdd,2,4);
    sprintf(filename,"./bdd/graph.dot");
    write_dd(gbm,bdd,filename);
    Cudd_Quit(gbm);
    return 0;       
}

I am getting some error during compilation.

 gcc -I /home/subhadip/cudd-3.0.0 -I /home/subhadip/cudd-3.0.0/util -I /home/subhadip/cudd-3.0.0/cudd transfer1.c /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1 
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAPI.o): In function `Cudd_ExpectedUsedSlots':
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1835: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1844: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAPI.c:1850: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddCache.o): In function `cuddCacheProfile':
/home/subhadip/cudd-3.0.0/cudd/cuddCache.c:816: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_LdblCountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:729: undefined reference to `powl'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddUtil.o): In function `Cudd_CountMinterm':
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/cuddUtil.c:595: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o): In function `EpdNormalizeDecimal':
/home/subhadip/cudd-3.0.0/epd/epd.c:834: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/epd/epd.c:834: undefined reference to `pow'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-epd.o):/home/subhadip/cudd-3.0.0/epd/epd.c:452: more undefined references to `pow' follow
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `cuddAnnealing':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:229: undefined reference to `log'
/home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a(cudd_libcudd_la-cuddAnneal.o): In function `siftBackwardProb':
/home/subhadip/cudd-3.0.0/cudd/cuddAnneal.c:671: undefined reference to `exp'
collect2: error: ld returned 1 exit status

I have tried to statically link the libraries but the there is a problem. How can I fix it?

Subhadip
  • 423
  • 8
  • 16
  • I am suspecting necessary cudd libraries not linked correctly. Are you linking those statically or dynamically? – Vagish May 15 '19 at 10:01
  • I am linking the library during the compilation by adding the path of cudd.h, util.h and configure file with gcc. Is that the source of problem ? But , I think libraries are linked properly because , when I have tried the trivial program of displaying "Hello World" using those headers in the program , it worked properly. – Subhadip May 15 '19 at 10:05
  • `I am linking the library during the compilation by adding the path of cudd.h` - no you are not. There are no `-lcudd` or similar lines in your command. You are setting include search paths with `-I` commands. Not linking. Can you post the output of `find /home/subhadip/cudd-3.0.0 -name '*.so` or similar? Are there any shared libraries inside `cudd-3.0.0`? How did you configured and compiled cudd library? – KamilCuk May 15 '19 at 10:09
  • @KamilCuk I have used ./configure, make, make check to configure the cudd library. I am not sure if there is any shared library in cudd-3.0.0. – Subhadip May 15 '19 at 10:17
  • So, according to the README (which I hope you read), you have built the static libraries. So find them. You search for files with `.a` extension, ie. `find /home/subhadip/cudd-3.0.0 -name '*.a'`, probably `cudd.a` or `libcudd.a`. ( I think it's probably in the `.libs` directory, but that's a guess ). – KamilCuk May 15 '19 at 10:20
  • @KamilCuk I found the following as you have told. /home/subhadip/cudd-3.0.0/cplusplus/.libs/libobj.a /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a /home/subhadip/cudd-3.0.0/dddmp/.libs/libdddmp.a . Now what should I do to fix the problem ? – Subhadip May 15 '19 at 10:28

2 Answers2

1

You compiled cudd and generated a static library. Now you need to link with it:

gcc .. <other options> ... transfer1.c /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1

Note that the order of files matter.

I can guess that for C++ support you have to link with cplusplus/.libs/libobj.a and for dddmp support you need symbols exported in dddmp/.libs/libdddmp.a.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • I used ` gcc -I /home/subhadip/cudd-3.0.0 -I /home/subhadip/cudd-3.0.0/util -I /home/subhadip/cudd-3.0.0/cudd transfer1.c -I /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1 ' . But I am getting the same error. – Subhadip May 15 '19 at 10:46
  • 1
    Not `-I`, there is no `-I` before `.a` file in my command. Just treat the `.a` file as a source file. `gcc -I /home/subhadip/cudd-3.0.0 -I /home/subhadip/cudd-3.0.0/util -I /home/subhadip/cudd-3.0.0/cudd transfer1.c /home/subhadip/cudd-3.0.0/cudd/.libs/libcudd.a -o transfer1` – KamilCuk May 15 '19 at 10:57
  • I have tried with the command which you have mentioned. This time I am getting different set of errors. So I have modified the question and mentioned it there. – Subhadip May 15 '19 at 11:15
  • 2
    You need to link math library. Add `-lm` after `.a` file. `.../.libs/libcudd.a -lm -o transfer1`. `log` calculates logarithm and `exp` calculates e-base exponential function value and `pow` takes a number to the power of another number. These are function from the C standard math library. – KamilCuk May 15 '19 at 11:17
  • It compiled. But during running I get some segmentation fault. Now the output is : DdManager nodes: 4 | DdManager vars: 1 | DdManager reorderings: 0 | DdManager memory: 10523080 : 3 nodes 2 leaves 2 minterms ID = 0x9bc15 index = 0 T = 1 E = 0 1 1 Segmentation fault (core dumped) – Subhadip May 15 '19 at 11:21
  • Well, your code may be full of errors, you didn't check any return values and such. Good luck. I have none experience in CUDD library. You can ask another question if you can't resolve your problem, maybe someone willing and experienced in CUDD will come by. – KamilCuk May 15 '19 at 11:28
  • Well, By checking the return value , are you referring if fopen() returns NULL then we should terminate ? – Subhadip May 15 '19 at 11:31
  • `fopen` `malloc` `Cudd_Init` `Cudd_bddNewVar` and `Cudd_BddToAdd` . All functions that return value that can be checked for errors. – KamilCuk May 15 '19 at 11:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/193391/discussion-between-subhadip-and-kamil-cuk). – Subhadip May 15 '19 at 11:34
1

After using the above solution, if the error still persists, For me, I have not made the folder named 'bdd' in the proper location for the code line:

sprintf(filename, "./bdd/graph.dot");

Now, it is executing for me.

Aadil Hoda
  • 592
  • 7
  • 17