CAPD::DynSys Library  6.0.0
Building your own programs

To build your own programs we recommend use of attached script that are generated according to your system configuration. It provides compiler flags (parameter -—cflags ) or/and linker flags with all necessary dependencies (parameter -—libs).

After successful building the library the script is located in bin sudirectory.

After call

make install

this script is 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++ MyProgram.cpp -o MyProgram `capd-config --cflags --libs`
Definition: ApplicationDesc.h:23

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

Note
The CAPD library is built with -std=c++17 -O2 options. Both flags are returned by -—cflags

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__ -std=c++17 -frounding-math -I/home/user/capd -L/home/user/capd MyProgram.cpp -o MyProgram -lcapd -lfilib
Definition: Logger.h:88
Note
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.

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

# path to directory, where script capd-config is located
CAPDBINDIR =/home/user/capd/build/bin/

# setting compiler and linker flags
CAPDCXX := $(shell $(CAPDBINDIR)capd-config --variable=capd_cxx)  
CAPDFLAGS = `${CAPDBINDIR}capd-config --cflags`
CAPDLIBS = `${CAPDBINDIR}capd-config --libs`
CXXFLAGS += ${CAPDFLAGS} 

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

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

OTHERS_OBJ = ${OTHERS:%=${OBJDIR}%.o}
OBJ_FILES = ${OTHERS_OBJ} ${PROGS:%=${OBJDIR}%.o}

.PHONY: all
all: ${PROGS}

# rule to link executables
${PROGS}: % : ${OBJDIR}%.o ${OTHERS_OBJ}
        ${CAPDCXX} -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}
        $(CAPDCXX) ${CXXFLAGS} -MT $@ -MD -MP -MF ${@:%=%.d} -c -o $@ $<

# rule to clean all object files, dependencies and executables
.PHONY: clean
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.