Building Pyramids

Matt Polnik's blog

MiniZinc Installation on Debian


MiniZinc is a platform for developing Constraint Programming models and solving discrete optimization problems. In this post, we describe the MiniZinc installation on Debian Stretch. Despite the targeted operating system, steps presented below should be easily portable to other Linux distributions.


MiniZinc is distributed using a bundle that contains a compiler, a development environment, and the Gecode solver. The bundle can be downloaded from the official project websiteor the permanent link that always points to the latest release of the bundle.

Unfortunately, the precompiled Gecode solver binaries from the bundle do not work on Linux distributions that come with the version of the Qt framework older than 5.9. For example, an attempt to run MiniZinc on Debian Stretch ends prematurely with the runtime failure.

minizinc --solver Gecode /vagrant/test_model.mzn /vagrant/test_data.dzn 
/opt/minizinc/2.2.3/MiniZincIDE-2.2.3-bundle-linux/bin/fzn-gecode: error while loading shared libraries: cannot open shared object file: No such file or directory

An inspection of libraries required by the fzn-gecode executable narrows down the problem to a single issue: version 'Qt_5.9' not found.

ldd /opt/minizinc/2.2.3/MiniZincIDE-2.2.3-bundle-linux/bin/fzn-gecode
/opt/minizinc/2.2.3/MiniZincIDE-2.2.3-bundle-linux/bin/fzn-gecode: /usr/lib/x86_64-linux-gnu/ version 'Qt_5.9' not found (required by /opt/minizinc/2.2.3/MiniZincIDE-2.2.3-bundle-linux/bin/fzn-gecode) (0x00007ffd907f1000) => not found => /usr/lib/x86_64-linux-gnu/ (0x00007fb453aa3000) => /usr/lib/x86_64-linux-gnu/ (0x00007fb45356a000) => /usr/lib/x86_64-linux-gnu/ (0x00007fb45309b000)

We should not install a new version of Qt and replace the default version available in our system to avoid library conflicts with other Qt applications that have been already installed. Instead, we build the Gecode solver using the older Qt library and overwrite the Gecode solver binaries in the MiniZinc bundle. The steps below show a complete installation process of MiniZinc on Debian Stretch. For modifying filesystem outside our home directory and installation of the Gecode build-time dependencies, we need “sudo” permissions.


  1. Download and install the MiniZinc bundle for Linux. The following commands install the MiniZinc bundle in the /opt/minizinc/2.2.3 directory.
    sudo mkdir -p /opt/minizinc/2.2.3
    sudo tar -xf MiniZincIDE-2.2.3-bundle-linux-x86_64.tgz -C /opt/minizinc/2.2.3
    rm MiniZincIDE-2.2.3-bundle-linux-x86_64.tgz
  2. Create a symbolic link to the minizinc executable.
    sudo ln -s /opt/minizinc/2.2.3/MiniZincIDE-2.2.3-bundle-linux/bin/minizinc /bin/minizinc
  3. Checkpoint. Print the version of the minizinc library.
    vagrant@stretch:~$ minizinc --version

    You should see similar output.

    MiniZinc to FlatZinc converter, version 2.2.3, build 34907429
    Copyright (C) 2014-2018 Monash University, NICTA, Data61
  4. Install dependencies required for the Gecode solver compilation.
    sudo apt-get --yes install g++-6 cmake qt5-qmake qtbase5-dev qtbase5-dev qtdeclarative5-dev qt5-default
  5. Download, compile and install the Gecode solver. The following commands download the latest version of the Gecode solver, as of writing this post, compile the project using default settings, and install it in the /opt/gecode-6.1.0 directory.
    wget --quiet
    tar -xf release-6.1.0.tar.gz
    rm release-6.1.0.tar.gz
    cd gecode-release-6.1.0 && ./configure --prefix=/opt/gecode-6.1.0 --enable-gist && make -j 4 && sudo make install
  6. Create a symbolic link to the fzn-gecode executable.
    cd /usr/bin && sudo ln -s /opt/gecode-6.1.0/bin/fzn-gecode fzn-gecode
  7. Add the Gecode shared libraries to the linker. This step is required for the fzn-gecode program that loads the Gecode shared libraries at runtime.
    echo '/opt/gecode-6.1.0/lib' | sudo tee /etc/ && sudo ldconfig
  8. Remove the fzn-gecode executable from the MiniZinc bundle.
    cd /opt/MiniZincIDE-2.2.3-bundle-linux/bin/ && sudo rm fzn-gecode 
  9. Checkpoint. Test the installation by solving a simple optimization problem.
    1. Create the test_model.mzn file with the following content.
      enum Item;
      int: weight_limit;
      array[Item] of int: value;
      array[Item] of int: copies;
      array[Item] of int: weight;
      array[Item] of var int: selected_copies;
      var int: total_value;
      % test to ensure that the constraint library works
      include "globals.mzn";
      constraint forall(i in Item) (selected_copies[i] >= 0 /\ selected_copies[i] <= copies[i]);
      constraint sum([selected_copies[i] * weight[i] | i in Item]) <= weight_limit;
      constraint total_value = sum([selected_copies[i] * value[i] | i in Item]);
      solve maximize total_value;
      output ["knapsack = \(selected_copies);\n", "total_value = \(total_value);"];
    2. Create a data sample and save it as the test_data.dzn file.
      Item = {Mask, Relievo, Soldier, Plate};
      value = [13, 7, 1, 10];
      weight = [7, 3, 2, 5];
      copies = [1, 1, 3, 2];
    3. Solve the optimization problem using the Gecode solver.
      minizinc --solver Gecode /vagrant/test_model.mzn /vagrant/test_data.dzn 
    4. You should see the following output.
      knapsack = [0, 0, 0, 2];
      total_value = 20;

      The bar ========== means that the last printed solution has been proven optimal.


This post demonstrated a general technique for dealing with missing shared libraries in Linux. We used the ldd command to list the missing shared libraries of a given executable. In case of Qt, rather than installing the missing version of the library which would lead to conflict with other software packages, we built the Gecode solver from sources and linked it against the Qt platform for our operating system. For convenience, we created symbolic links to run the minizinc and fzn-gecode utilities from a command line without specifying their exact location. Finally, we registered the shared libraries of Gecode by creating the /etc/ file and reloaded the linker configuration. To confirm that Minizinc has been installed correctly, we compiled and solved a simple optimization problem.

Overall, the MiniZinc platform, installed in this post, is an attractive technology for modeling and solving discrete optimization problems. It was developed for fast prototyping several models for solving a problem and testing them on different solvers. I strongly recommend MiniZinc to anyone who works with discrete optimization problems. I found it very helpful especially in making informative decisions which variant of a model to implement in the native solver technology. In my personal opinion the best way to learn MiniZinc is taking the Coursera courses: Basic Modeling for Discrete Optimization, Advanced Modeling for Discrete Optimization, and Solving Algorithms for Discrete Optimization. First few classes of the first course should already give you intuition what the MiniZinc is and whether it may be helpful to you.