GLPK/Linux OS

This page explains how to build and install GLPK on a Linux operating system. The standard compiler suite on Linux is GCC. Notwithstanding, other compilers can be installed and used.

Pre-packaged option: as an alternative, GLPK may also be available as a Debian (used by Ubuntu) or RPM (used by Fedora) package. Installing a package is more convenient than compiling, but packages tend to lag behind by one or more releases. Manual compilation also allows you to customize your build configuration so that the resulting library can better match your circumstances and needs.

New users are therefore encouraged to build GLPK from source. Assistance, should you need it, is always available from the help-glpk mailing list.

Key files
The key GLPK files in relation to Linux are shown in the following table:

Note: if GLPK was added as a Linux package, then the "/local" part is omitted from the paths indicated.

Caution: API users should not include GLPK headers other than glpk.h.

The path details shown assume a normal build and install. The static library is used for compile-time linking and the shared library is used for runtime linking. Depending on how GLPK was configured, both need not be present. Users sometimes encounter problems with file locations and search paths &mdash; if so, some troubleshooting hints are given below. The locations used by GLPK comply with the Linux filesystem hierarchy standard.

Installation procedure
The following instructions refer to:
 * a representative upgrade from GLPK version 4.42 to version 4.65.

Please note:
 * if you are undertaking a new install, then skip any instructions relating to 4.42
 * for later releases, the 4.65 should be replaced by the relevant version number.

Prerequisites
For compilation gcc is needed. GCC is the GNU Compiler Collection. This collection includes a C language compiler. You can check the installed version with:

$ gcc --version

Using ODBC requires either the iODBC or the unixODBC package.

The default installation path is /usr/local. On Fedora derived distributions (Fedora, Red Hat, Centos, ...) /usr/local/lib is not in the library search path by default. You can add the path with:

$ sudo su
 * 1) echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
 * 2) /sbin/ldconfig
 * 3) exit

Obtain source
Download the GLPK 4.65 tarball to a directory within your user space (skip ahead if you already have it):

$ wget ftp://ftp.gnu.org/gnu/glpk/glpk-4.65.tar.gz $ wget ftp://ftp.gnu.org/gnu/glpk/glpk-4.65.tar.gz.sig

Verify the tarball: $ gpg --verify glpk-4.65.tar.gz.sig glpk-4.65.tar.gz

If the key is missing in your keyring, you can install it with: $ gpg --recv-keys 5981E818

Then unpack the tarball: $ tar -xzvf glpk-4.65.tar.gz $ cd glpk-4.65

Apply any subsequent patches &mdash; rarely needed as important bug fixes normally trigger a new release.

Research
Hunt for the PDF documentation (or else change to subdirectory doc and look):

$ find. -name "*.pdf" -print

It is strongly recommended that you familiarize yourself with "Installing GLPK on Your Computer" from <tt>doc/glpk.pdf</tt> before proceeding. View it as follows:

$ evince doc/glpk.pdf &

Alternatively, similar information is available in text form:

$ less INSTALL       # q to quit

Configure
Next determine which configuration options you want to use. For instance, support for ODBC (Open Database Connectivity) allows MathProg to interact with relational databases and spreadsheets. List the options (the <tt>less</tt> pipe provides scrolling, hit <tt>q</tt> to quit):

$ ./configure --help | less

Install any dependent Linux packages using your system package manager. For example, ODBC requires that the appropriate ODBC dev (developer) header files package is present.

Now configure GLPK. By default, GLPK builds both static and shared versions of the library. Common options include (you need just one of these commands):

$ ./configure                             # default $ ./configure --enable-dl --enable-odbc   # for ODBC support with dynamic linking to ODBC library $ ./configure --disable-shared            # prevent GLPK shared library

The configuration option <tt>--enable-dl</tt> does not instruct GLPK to build a shared library, rather it tells GLPK to link dynamically with its supporting libraries.

If you need to set environment variables, do so on the configure command-line after any configuration options &mdash; use <tt>--help</tt> for more details.

Do not use paths containing whitespace characters as these are not supported by <tt>automake</tt>.

Compile
Now compile and check GLPK. The <tt>make</tt> option <tt>--jobs=4</tt> allows parallel processing on multi-core hardware &mdash; it should be omitted on single-core (older) machines or when encountering error messages. Depending on your CPU power, the compilation step may take from 15 seconds to several minutes.

$ make --jobs=4 $ make check OPTIMAL LP SOLUTION FOUND

Check the local GLPSOL version:

$ examples/glpsol --version GLPSOL: GLPK LP/MIP Solver, v4.65

Install
System installation makes GLPK generally available to all users, but does require sudo privileges. System installation is optional and can be omitted.

Uninstall GLPK 4.65 if present (steps one and three may not be necessary):

$ tar -xzvf glpk-4.65.tar.gz $ cd glpk-4.65 $ ./configure $ sudo make uninstall

It is not strictly necessary to uninstall previous versions of GLPK, but it is good practice.

Install GLPK 4.65:

$ sudo make install Libraries have been installed in: /usr/local/lib

Check the expected files exist:

$ ls -lF /usr/local/lib/libglpk.a $ ls -lF /usr/local/lib/libglpk.so

Check GLPSOL is generally available:

$ which glpsol /usr/local/bin/glpsol

Update the runtime linker cache (may not be necessary):

$ sudo ldconfig --verbose

Mop-up
Finally, clean up the GLPK 4.65 source directory:

$ make clean         # the Makefile remains, unlike distclean

And delete the obsolete branch as required (the original GLPK 4.65 tarball will remain if present):

$ cd ~/glpk $ rm -fr glpk-4.65

That's it!

Source code
The source code contains more information on the build process including some useful configuration options:

$ less INSTALL       # q to quit

Performance tuning
When compiling GLPK with GCC on a x86 architecture a performance gain of 20 % can be gained by compiling with option <tt>-mfpmath=both</tt>. This requires SSE to be enabled. This is default for the x86-64 compiler. For the 32bit compiler SSE has to be enabled by either of <tt>-march=&lt;cpu-type></tt>, <tt>-msse</tt>, or <tt>-msse2</tt>.

<tt>-mfpmath=both</tt> allows both the FPU and the SSE registers to be used. See http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/i386-and-x86_002d64-Options.html

Example:

$ export CFLAGS="-march=native -O3 -pipe -mfpmath=both" $ ./configure --enable-dl --enable-mysql --enable-odbc $ make -j8 $ make check $ sudo make install $ sudo ldconfig


 * <tt>-march=native</tt> implies that the code may not be used on different CPUs.
 * <tt>-pipe</tt> reduces compile time by using pipes instead of files
 * <tt>-j8</tt> reduces compile time by parallelization, assumes 8 cores

Troubleshooting
To hunt for key GLPK files on your system, try:

$ find -P /usr -name "*glpk.*" \( -type f -o -type l \) -exec file '{}' \; 2>/dev/null

To check your current search paths, try:

$ printenv | grep PATH

Both the above calls are passive and cannot change your system.

You may need to explicitly update the runtime linker cache:

$ sudo ldconfig --verbose