Table of Contents

Gecode Installation Instructions

Download the latest version of Gecode. Download the sources and proceed as detailed in Sec. 2.6.2 of MPG "Compiling Gecode" and the supplementary information below. Do not install the binaries or via apt-get, these are often outdated versions. In particular, make sure you compile with Gist in order to visualize the search tree. This will require that the QT library is also present in your machine.

Linux:

Download the sources using the .tar.gz file or the svn command given in the download page.

In ubuntu, to install the QT libraries that are needed by Gist, install via apt-get the packages libqtcore4, libqt4-dev and qt4-qmake (but check for newer versions, eg, qtN, N>4). You can also install the latest version from the Qt web page (in which case be aware to set the correct path to the libraries).

sudo apt-get install libqtcore4 libqt4-dev qt4-make

Then, uncompress the tar.gz file in a directory of your choice (for example, /opt or ~/opt) and enter the directory. Run:

./configure --prefix=${PWD}
make

The make command will take a while. If it runs without errors then you are ready to work. Do not run make install, as we prefer keeping the installation in the directory you chose.

To testing your installation, enter in the directory examples/ and execute, for example, money --help. Read in the output the version of your gecode installation and make sure it matches the one you downloaded. Make also sure Gecode is installed with Gist. The following output is expected:

Gecode configuration information:
- Version: 4.4.0
- Variable types: BoolVar IntVar SetVar FloatVar 
- Trigonometric and transcendental float constraints: disabled
- Thread support: enabled (8 processing units)
- Gist support: enabled

Run then a couple of tests:

money
money -mode gist

The latter command should open the window with the search tree visualization.

If something goes wrong with the attempts above, try setting this enviornment variable:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${GECODE_HOME}

GECODE_HOME contains the path to the directory where you have gecode. If that resolves the problem you may want set the command in the shell starting commands ~/.bashrc to avoid retyping the command everytime a new shell is started.

You are now ready to compile your own scripts. Copy one of the examples in a working directory of your choice. In Linux, to compile your own scripts read section 2.3.3 of MPG linked below or use this [./Makefile.unix][Makefile]]. The makefile should already handle the dynamic linking via rpath. Alternatively you have to set:

# change to your Gecode installation path here:
GECODE_HOME=${HOME}/opt/gecode/release
# Assumes standard installation of Qt via apt-get
# QT_LIB = /usr/lib/x86_64-linux-gnu
# QT_INCL = /usr/include/qt4
# QT_LINKS = -lQtGui -lQtCore

GECODE_LINKS=-lgecodegist -lgecodeint -lgecodesearch -lgecodekernel -lgecodesupport -lgecodedriver -lgecodeminimodel -lgecodeset 

LINKER=g++
COMPILER=g++ 


%: %.cpp
	${COMPILER} -I${GECODE_HOME} -I/usr/share/qt4/mkspecs/linux-g++-64 -I${QT_INCL}/QtCore -I${QT_INCL}/QtGui -I/usr/include/qt4 -I. -c -o $@.o $@.cpp
	${LINKER} -o $@ $@.o -L${GECODE_HOME} ${GECODE_LINKS} -lpthread 

# -Wl,-rpath,${GECODE_HOME} 

clean:
	rm -fr *.o

If compilation creates problems but the examples were executing fine, then, try the following. From the examples directory remove the exectuable of an example, go to the directory above, and execute make compileexamples. You can copy the two lines that execute for the compilation in your Makefile and use those to compile your script.

If the problem is linking the QT libraries, i.e., if you observe an error message /usr/bin/ld: cannot find -lQtGui then you probably need to change the path to the Qt libraries. To find out where your libraries are, try:

locate libQtGui.so

MacOsX

From source

You can install from source as follows.

First, install the QT libraries. Remeber the directory of installation.

Test installation by ensuring qmake and moc executable are available from command line. If not add to the PATH the path to the Qt library:

export QT_HOME=/path/to/yourQt
export PATH=$PATH:${QT_HOME}/5.7/clang_64/bin

Change QT_HOME with the path to your Qt library installation. For example, in my case: QT_HOME=/Users/marco/Library/Qt/5.7/clang_64/. Then download the gecode package .tar.gz and uncompress it in a directory of your choice. For example:

mkdir opt
cd opt
tar xzvf gecode.tar.gz

Enter in the new created directory and execute:

./configure

Make sure that in the output of ./configure you have Qt support... yes and build Gist... yes. Then, continue:

make CXXUSR="-std=c++11"

If everything succeeded you will be asked to run make install but do not do that since we want to use the local installation.

You could now test the examples. For example, example/money. Most liekly this will not work. To make it work copy an example in a working directory of your choice and compile it as follows:

g++ -c -I${GECODE_HOME} money.cpp
g++ -L${GECODE_HOME} -o money money.o -lgecodedriver -lgecodesearch -lgecodeminimodel -lgecodeint -lgecodekernel -lgecodesupport -lgecodegist -Wl,-rpath,${QT_HOME}/lib

The following should now work:

./money -mode gist

To automatize the compilation process, create a Makefile in the same directory where the script is.

QT_HOME=/Users/marco/Library/Qt/5.7/clang_64/lib
GECODE_HOME=/opt/gecode/release


GECODE_LINKS=-lgecodegist -lgecodeint -lgecodesearch -lgecodekernel -lgecodesupport -lgecodedriver -lgecodeminimodel -lgecodeset 

COMPILER=clang++
LINKER=clang++

CXXFLAGS+=-Qunused-arguments -ffinite-math-only -fno-math-errno -fno-strict-aliasing -O3 -fvisibility=hidden -ggdb -pipe -Wall -Wextra -fPIC -pthread -DNDEBUG

%: %.cpp
    ${COMPILER} -I${GECODE_HOME} -Wfatal-errors ${CXXFLAGS} -c $@.cpp
    ${LINKER}$ -o $@ ${LDFLAGS} -L${GECODE_HOME} $@.o ${GECODE_LINKS} -Wl,-rpath,${QT_HOME}

clean:
	rm -fr *.o

Remember to edit QT_HOME and GECODE_HOME to point at the right paths. Moreover make sure that the indentation in the indented lines is a tab and not spaces.

From .dmg package

You can also install via .dmg package. The installation in this case is standard. There will be a gecode.framework installed in your system under /Library/Frameworks/. You will also see a directory C++ Examples that you can copy somewhere. To compile the examples and your scripts follow the instructions in section 2.3.2.

g++ -c money.cpp
g++ -framework gecode -o money money.cpp

If it does not work, try:

g++ -c -stdlib=libstdc++ money.cpp 
g++ -stdlib=libstdc++ -framework gecode -o money money.cpp

To automatize the compilation process, create a Makefile in the same directory where the script is.

COMPILER=clang++
LINKER=clang++
CXXFLAGS+=-Qunused-arguments -ffinite-math-only -fno-math-errno -fno-strict-aliasing -O3 -fvisibility=hidden -ggdb -pipe -Wall -Wextra -fPIC -pthread -DNDEBUG


%: %.cpp
    ${COMPILER} -I${GECODE_HOME} -Wfatal-errors ${CXXFLAGS} -c $@.cpp
    ${LINKER}$ -o $@ -framework gecode ${LDFLAGS} $@.o

clean:
	rm -fr *.o

Make sure that the indentation in the indented lines is a tab and not made by spaces.

Windows

  • Follow the instructions in section 2.6.2 of MPG. Ensure you have the gist mode functioning. Report back if you encounter problems.

Integration with text editors

It will be very helpful to get acquainted with a good text editor or software development tool. Installing Gecode requires ensuring that the installation works with the Integrated Development Environment chosen. The following is a list of possibilities:

Visual Studio Code

Free editor based on Node.js that work on all systems (OSX, Linux and Windows).

The best way to get started with VS Code is to watch the introductory videos linked after the download of the program. To exploit the potential of VS Code for C++ read this preview page. Also this blog entry is relevant.

Atom Editor, free editor based on Node.js that works on all systems

(OSX, Linux and Windows)

Visual Studio Community, free but only for Windows

Links

Author: Marco Chiarandini

Created: 2016-09-14 Wed 09:09

Validate