Static compilation of cpuminer

If you want to compile cpuminer statically, you will notice it fails quite fast with the output similar to:

This is because you don't have the right version of libraries and development packages installed in your system.

To compile cpuminer statically, you will need to:

  • compile and install OpenSSL
  • compile and install curl (libcurl)
  • slightly modify cpuminer compilation flags

Compiling will make a bit of a mess in your system - lots of packages installed, and compiling from source leaves lots of things on your system (depending how much time you want to invest in it).

Therefore, it's easiest if you compile in a separate VM (i.e. KVM) or container (i.e. LXD).

Also, you may want to use a new version of gcc - in theory, newer gcc produces slightly faster binaries.

Compilation below was made on Ubuntu 17.10, but should also work on other Ubuntu flavours and on Debian, and with little modifications (installed package names) on other distributions, like CentOS, Fedora etc.

OpenSSL compilation

You have to compile OpenSSL first - because libcurl will use it.

In the "config" file, make sure to add options= line as in a diff below, around line 644:

Run ./config and make sure no-shared option is listed (marked <----- here below):

Finally, run make and make install - the process should finish without any errors:

curl / libcurl compilation

Run ./buildconf - you may need to install a couple of extra packages - like in an example below. Typically, you will need to install autoconf and libtool packages. Make sure they are all installed and ./buildconf runs without errors:

Run ./configure with --disable-shared flag - it should finish without errors, and you should see "Build libcurl: Shared=no, Static=yes" in the summary at the end:

Finally, run:

cpuminer compilation

Now, we can compile cpuminer. We will use cpuminer-opt below:

Open "" file and change it as in the diff below (added LDFLAGS="-static"):

Now, run ./ to compile a static version of cpuminer - the command should finish without any errors:

To verify the binary was compiled as a static one, run "file" - you should see "statically linked" in the output:

If on the other hand you see "dynamically linked" - it means that it's not a static compilation of cpuminer:

testing / benchmarking

To see if it's running, use:

"Illegal instruction" when trying to run on a different server

The binary may fail to run with "Illegal instruction" if it was compiled on a server with CPU newer than the one you're trying to run it now.

When you start cpuminer in benchmark or in real running mode, you will see it prints some CPU features, and "SW features", among other things:

If your CPU features are lower than SW features (i.e. if the CPU does not support AVX2), the program will crash with "Illegal instruction".

Solution: building a binary with different "-march" flags. Examples are given in README.txt file:

Simply edit file, and change -march=native i.e. to -march=corei7-avx.

For example, a binary built with -march=core2 will give the following output:

"FATAL: kernel too old" when trying to run on a different server

The following means that you compiled cpuminer on a much newer operating system (i.e. cpuminer was compiled on Ubuntu 17.10, which is kernel 4.13, but you're trying to run it on CentOS 6, which is kernel 2.6.18):

Try building a binary on a similar system.

common compilation errors

  • ./../depcomp: line 611: exec: g++: not found

Install g++ package.

  • cc1plus: error: unrecognized command line option "-std=gnu++11"

Your compiler is too old. Most likely you won't be able to build without some big changes in cpuminer code.

  • algo/m7m.c:4:10: fatal error: gmp.h: No such file or directory

Install libgmp-dev package.

  • /usr/bin/ld: cannot find -lz

Install zlib1g-dev package.

  • algo/m7m.c:206:5: error: unknown type name 'mp_bitcnt_t'; did you mean '__blkcnt_t'?

Your gmp library is too old (probably compiling on CentOS 6?).

Remove any gmp library development files, download the sources and compile:

  • timeval.c:(.text+0xf): undefined reference to `clock_gettime

You may see it when building on CentOS 6. Add -static to CXXFLAGS in

and add -lrt in, around line 181: