CAPD DynSys Library  4.0
Building your own programs

To build your own programs we recommend use of attached scripts that are generated according to your system configuration. They provide compiler flags (parameter –cflags ) or/and linker flags with all dependencies (parameter –libs).

script name version of CAPD library
capd-config double precision without graphics, without CAPD::RedHom
capd-gui-config with krak graphical library
mpcapd-config with multiple precision support
mpcapd-gui-config with krak and multiple precision
capdRedHom-config CAPD::RedHom library

Those scripts are installed into <prefix>/bin directory. We assume that this location is on the search path of your system so that scripts can be called by its name (if not in the example below you need to provide full path to them).

One file programs

Assume that you want to build your MyProgram.cpp that uses double version of CAPD.

Then the instruction might be something like

g++ -O2 MyProgram.cpp -o MyProgram `capd-config --cflags --libs`

if g++ is your C++ compiler and you want configuration from capd-config.

Compilation without scripts

It is possible to compile your program without our scripts. But then command line strongly depends on your system configuration.

Assume that the CAPD library was installed to /home/user/capd and it uses intervals from filib library then the instruction might be

g++ -O2 -D__USE_FILIB__ -frounding-math -I/home/user/capd -L/home/user/capd MyProgram.cpp -o MyProgram -lcapd -lprim
Observe that without option -frounding-math compiler can optimize code so that it is not rigorous anymore.
Option -D__USE_FILIB__ is an internal CAPD flag to use filib intervals. If you forgot to pass it to compiler then header files will differ from those used to compile CAPD library.

Proper options for current configuration are returned by capd-config –cflags.

The command line becomes more complicated if your program uses graphics and/or multiprecision (e.g. see output of mpcapd-gui-config –cflags).

Multifile project

The example can be found in capd/capdMake/examples/projectStarter directory.

Assume that in the some directory we have project that contains:

  • MyProgram.cpp, YourProgram.cpp - source files that contains main function
  • utils.cpp, utils.h, output.cpp, output.h - source and header files that are used by the above programs,
  • the CAPD library was installed to /home/user/capd

To compile all source files create in the project directory a file Makefile that contains the following code (all indents need to be made by tabulators not spaces!!!)

# a list of all the programs in your project
PROGS = MyProgram YourProgram

# a list of all your units to be linked with your programs (space separated)
OTHERS = utils output

# directory where capd scripts are (e.g. capd-config)
CAPDBINDIR =/home/user/capd/bin/

# setting compiler and linker flags
CAPDFLAGS = `${CAPDBINDIR}capd-config --cflags`
CAPDLIBS = `${CAPDBINDIR}capd-config --libs`

# directory where object and dependancy files will be created
OBJDIR = .obj/

#============ the following should not be changed =========


.PHONY: all
all: ${PROGS}

# rule to link executables
${PROGS}: % : ${OBJDIR}%.o ${OTHERS_OBJ}
  ${CXX} -o $@ $< ${OTHERS_OBJ} ${CAPDLIBS}

# include files with dependencies
-include ${OBJ_FILES:%=%.d}

#rule to compile .cpp files and generate corresponding files with dependencies
${OBJ_FILES}: ${OBJDIR}%.o : %.cpp
  @mkdir -p ${OBJDIR}
  $(CXX) ${CXXFLAGS} -MT $@ -MD -MP -MF ${@:%=%.d} -c -o $@ $<

# rule to clean all object files, dependencies and executables
.PHONY: clean
  rm -f ${OBJDIR}*.o ${OBJDIR}*.o.d ${PROGS}

Then by calling make you will compile all source files and link all programs defined by PROGS variable. It will also create a list of dependencies (list of header files that it uses) for each source file so that next time source file will be recompiled only if itself or some of its dependencies has changed.