Search code examples
ccompiler-errorscompilationcudd

CUDD package : problems compile and makefile


I'm trying to run a simple program to learn how to use the CUDD package version 3.0.0. I downloaded the package and installed it: ( 1- ./configure 2- make 3- make check).

I created the following simple program :

  #include <stdio.h>
  #include "cudd.h"
  #include "util.h"

  int main (int argc, char *argv[])
  {
       printf("Its working");
       DdManager *gbm; /* Global BDD manager. */
       char filename[30];
       gbm = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); 
       DdNode *bdd = Cudd_bddNewVar(gbm); 
       Cudd_Ref(bdd); 
       Cudd_Quit(gbm);
       return 0;
   }

I would like create a makefile to compile it, How can I do it? Moreover, if I want compile it through the command line, how can I to link its libraries?


Solution

  • In version 3, CUDD got a major overhaul of its build system, so older HOWTOs for compiling programs that use CUDD are no longer applicable.

    To simplify the build process, I typically recommend to build against CUDD statically -- this allows you to run the later compiled program without giving the paths to the CUDD library and/or installing the CUDD library into "/usr/lib".

    To do so, first recompile cudd with:

     ./configure --enable-dddmp --enable-obj --enable-shared --enable-static; make
    

    This makes sure that the static library is build, along with the optional components of CUDD that you may later need.

    Then, you can compile your example program from the command line as follows:

    gcc test.c -o testprogram -I /path/to/cudd-3.0.0/cudd -I /path/to/cudd-3.0.0/util -I /path/to/cudd-3.0.0/ -static -L /path/to/cudd-3.0.0/cudd/.libs/ -lcudd -lm
    

    There are other ways of compiling against CUDD, but I'm personally not a big fan of globally installing libraries. If you start to use more features of CUDD, you may have to add more include directories for the compiler to find the CUDD .h files, and more libraries may be needed. Note that all parameters starting with "-static" are linker parameters in the compilation command above, while the others are for the compiler - this is important to know when you start writing Makefiles to automate your build process. A sample Makefile looks as follows:

    CFLAGS = -I /path/to/cudd-3.0.0/cudd -I /path/to/cudd-3.0.0/util -I /path/to/cudd-3.0.0/
    LFLAGS = -static -L /path/to/cudd-3.0.0/cudd/.libs/ -lcudd -lm
    
    default: testprogram
    
    testprogram: test.o
        $(CC) test.o -o testprogram $(LFLAGS)
    
    test.o: test.c
        $(CC) test.c -c -o test.o $(CFLAGS)
    

    Please consult a more comprehensive documentation for how to write Makefiles or use an alternative build system. Note that in the above file, the "four spaces in a row" need to be tabs in order for the Makefile to work. If you store it in the same directory as "test.c" under the name "Makefile", running "make" should build the program.