I'm doing some heavy number crunching on one system and I'd like to compile (and finetune) a custom GMP 6.1.0 for the user launching the number crunching computation. Previously I had a Debian wheezy (7.6) system on which I installed a custom GMP lib while being root and modificating things left and right in the filesystem (because I didn't know any better). It ended up working: my custom GMP lib was crunching numbers about 15% faster than the stock GMP.

Now I installed a new Debian (Jessie 8.3) on that computer with the "stock" GMP (the one that comes with Debian Jessie):

# gcc --version
gcc (Debian 4.9.2-10) 4.9.2

# apt-get install libgmp10
# apt-get install libgmp-dev

Which is apparently GMP 6.0.0.

I'm compiling my number crunching program doing:

$ gcc crunch.c -o crunch.o -L/gmp_install/lib -lgmp

(I know I could probably gain some by messing with some parameters passed to GCC, but the big problem here is the "slowness" of the non-custom GMP).

I then invoke ./crunch.o and it works but it is 15% slower than my custom build GMP on my old system (using the exact same gcc compilation command pasted above on the exact same computer).

I'd now like to compile a custom GMP 6.1.0 again, but only accessible for the user running the heavy computation.

In other words: I'd now like to install a custom GMP cleanly instead of messing (while being root) with the entire filesystem.

But I don't understand what -L/gmp_install/lib refers to nor what -lgmp does either.

I take it the first steps I need to do are:

So how can I compile a custom GMP for one (non root) user account and how would I go about then compiling my crunch.c program?

1 Answer 1


You could use the following steps as normal user

tar xvjf gmp-6.1.0.tar.bz2
cd gmp-6.1.0
./configure --prefix=${HOME}/gmp/6.1.0
make install

This will install gmp in ~/gmp/6.1.0. Now if you want to use this version to compile software against or use it at runtime, you have to set some environment variables:

export CPATH=${GMP_DIR}/include:$CPATH

You could put that into your ~/.bashrc or in a separate file you source just before you want to use it, or write a wrapper script including your binary stuff. Other people like to use environment-modules for this kind of tasks.

The -lgmp argument tells your linker to link against the shared library libgmp.so and -L/gmp_install/lib means to search for libraries in /gmp_install/lib and in the well known paths (/lib, lib64, /usr/lib, /usr/lib64, ...).

The environment variables are used as follows:

  • LIBRARY_PATH should provide the same as the -L switch
  • CPATH provides an additional search path for the header files
  • LD_LIBRARY_PATH is needed for the runtime
  • thanks a lot, it works. Btw is the LIBRARY_PATH export supposed to append LD_LIBRARY_PATH or LIBRARY_PATH? Feb 24, 2016 at 1:48
  • Yes, you are right. I have corrected it in the answer.
    – Thomas
    Feb 24, 2016 at 6:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .