The most commonly used mining program for mining Monero at the moment is xmr-stak. Some time ago it was split into separate projects for xmr-stak-cpu and xmr-stak-gpu, but now they are both combined into xmr-stak.

This means that during compilation you have to set some options yourself to tell the compiler which parts of the system have to be compiled and which should be omitted. If you don’t specify the options, you will get error messages telling you which options are problematic. Then you can decide whether you want to remove an option or install it on your system.

To start compilation of xmr-stak, download the source code from their github repository:

git clone https://github.com/fireice-uk/xmr-stak.git

After you have done this, switch to a build folder and run cmake (if you want to try compilation with all default options):

cd xmr-stak
mdkir build
cd build
cmake ..

I created a build folder, because it allows me to delete all cmake files later easily if I want to change any configuration.

This will probably throw at least one error at you, because with the default options it tries to compile both OpenCL support for AMD graphics as well as CUDA support for NVidia graphics.

If you want to install xmr-stak for CPU support only, you want to run cmake with these options:

cmake .. -DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF

I also did not want the HTTP interface and since my Pool does not support SSL/TLS I also disabled OpenSSL support. Moreover, I set the mining currency to Monero.

Thus, for my CPU minder I ended up with these options:

cmake .. -DCUDA_ENABLE=OFF -DMICROHTTPD_ENABLE=OFF -DOpenCL_ENABLE=OFF \
-DOpenSSL_ENABLE=OFF -DXMR-STAK_CURRENCY=monero

If you want to compile xmr-stak with GPU support, things become a bit more tricky, because xmr-stak only supports versions of GCC up to version 6. However, on my system I already had GCC 7 set as the default compiler.

If you try to compile xmr-stak with versions of GCC higher than 6 (e.g. gcc-7) you will receive the error message:

/opt/cuda/include/crt/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions later than 6 are not supported!
 #error -- unsupported GNU version! gcc versions later than 6 are not supported!

In most tutorials people just set the environment variables CC and CXX to the correct version of gcc, but at first this did not work for me. The problem is that cmake does not seem to start from a fresh configuration if you re-run it. Thus, changing the location of the compiler binary did not have any effect and even though I changed CC and CXX and re-ran cmake .. it always used version 7 for compilation.

This is where the build folder comes in handy. We can just delete everything, set the environment variables correctly and re-configure everything.

rm -r .
export CC=/usr/bin/gcc-6
export CXX=/usr/bin/g++-6
cmake .. -DOpenCL_ENABLE=OFF -DMICROHTTPD_ENABLE=OFF -DCUDA_ENABLE=ON \
-DOpenSSL_ENABLE=OFF -DXMR-STAK_CURRENCY=monero

xmr-stak has an automatic donation of 2% in its source code. You might want to adjust the header file donate-level.hpp if you want to change this donation level (either higher or lower).

Finally, you can compile it with make. I personally did not use make install, but that’s a matter of preference. Without installation, you will find the binary in the folder xmr-stak/build/bin/xmr-stak.

If you run it, you will be guided through the configuration and xmr-stak will write configuration files for the next starts.

I do not maintain a comments section. If you have any questions or comments regarding my posts, please do not hesitate to send me an e-mail to blog@stefan-koch.name.