To build from source, binary or tarball?

By | May 2, 2016

It’s a lot quicker and less hassle to build from a tarball but lets face it, it’s just not as fun :). Let’s go through a simple sample process.

There is an open source code call cpuminer that turns your computer into a bitcoin miner. Back in the days, this is how bitcoin mining all started.

Getting the code

Google searching cpuminer will turn up 2 main links.

  • https://sourceforge.net/projects/cpuminer – executable binary
  • https://github.com/pooler/cpuminer/releases – tarball
  • https://github.com/pooler/cpuminer – source code

If you download the binary you can run the code straight away. If you use the tarball, it contains all the files and dependencies you need. If you want a challange, grab a copy of the source code. If you have git, you can run:

> git clone https://github.com/pooler/cpuminer.git

The First Step

Once you have the code, the first thing you want to do is to find the README file. Look for instructions on how to build it build the code based on your OS. I’ll focus on:

Basic *nix build instructions:
./autogen.sh # only needed if building from git repo
./nomacro.pl # only needed if building on Mac OS X or with Clang
./configure CFLAGS=”-O3″
make

If you run ./autogen.sh you should see this error:

configure.ac:124: error: possibly undefined macro: AC_MSG_ERROR If this token and others are legitimate, please use m4_pattern_allow.  See the Autoconf documentation.

Running ./nomacro.pl should result in no error and running ./configure CFLAGS=”-O3″ should result in this error:

checking for pthread_create in -lpthread... yes
./configure: line 5623: syntax error near unexpected token `,'
./configure: line 5623: `LIBCURL_CHECK_CONFIG(, 7.15.2, ,'

The error from ./configure has been documented in a few places. Particularly:

  • https://github.com/jgarzik/cpuminer/issues/33
  • https://github.com/pooler/cpuminer/issues/38
  • https://github.com/pooler/cpuminer/issues/14

The advice from the links above is to build from a tarball which is appropriate. However, if you want to dig deeper, you need to do the following:

Create a folder called m4

Create a folder called m4 and copy a file called libcurl.m4 into this directory. Then add string “ACLOCAL_AMFLAGS = -I m4” to file Makefile.am and edit file autogen.sh – replace string “aclocal” with “aclocal -I m4”.

Source: https://bitcointalk.org/index.php?topic=4823.0

Run brew install curl to install curl on your Mac. You should find libcurl.m4 in this location:

/usr/local/Cellar/curl/7.48.0/share/aclocal

Once you have done this, run all the commands again starting from ./autogen.sh and the code should compile.

If you want to run in debug mode via gdb, add the -g flag.

> ./configure CFLAGS="-g -O0"

This means you can then do gdb minerd

To execute the code, you’ll want to run something like this:

> ./minerd -0 url_of_your_pool -t 1 -u username -p password

For more info check out: http://www.coindesk.com/information/how-to-mine-litecoin/

Leave a Reply

Your email address will not be published.