ubuntu下从源码编译比特币(Bitcoin)客户端

在ubuntu下安装bitcoin的方法,在网上找到了这篇文章,经过我测试,可以正常安装和编译bitcon的源码。转来和大家分享一下。其实还是在linux下进行编译代码要方便很多。
在编译之前可能要先安装一些工具:
apt-get install make
apt-get install gcc
apt-get install g++
apt-get install libdb-dev
(libdb5.1-dev)
apt-get install libdb++-dev
(libdb++-dev libdb5.1++ libdb5.1++-dev)
apt-get install libboost-dev
(apt-get install libboost1.37-dev)
(apt-get install libboost-all-dev)
apt-get install zlib1g-dev
apt-get install libssl-dev
apt-get install build-essential
apt-get install libminiupnpc-dev
apt-get install autoconf
Get the source first
 
 
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
先得到源码。如果你的系统上没有安装git就先用
sudo apt-get install git-core
来安装这个软件

You can read doc/build-unix.md, or follow along.

This step should be no problem.

读这个doc文件,可以知道源码要怎么编译,然后生成编译源码所需要的库配置

 
 
./autogen.sh
This step may give you some issues…
./configure
运行完上边的这个命令之后,你就可以知道你的系统中都少什么库,下边就是安装缺少的库的方法
If you encounter configure: error: libdb_cxx headers missing
提示少libdb_cxx头,这个时候运行下边令命安装db的C++开发库
 
 
sudo apt-get install libdb5.1++-dev
If you encounter configure: error: Found Berkeley DB other than 4.8, required for portable wallets (–with-incompatible-bdb to ignore), run the following command instead. You can always send your bitcoins to another wallet.
如果提示安装的DB不是4.8的版本,则使用下边的命令跳过DB的版本检测
 
 
./configure --with-incompatible-bdb
If you encounter checking for boostlib >= 1.20.0… configure: We could not detect the boost libraries (version 1.20 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to –with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.
上边的意思是boostlib库的一些问题,如果你用的是一个静态boost库,你要设置环境变量,如果你确定已经安装了boost库,那就看一下自已的库版本是否>=1.20.0。安装boost库可以使用下边的命令
 
 
sudo apt-get install libboost-all-dev
This time you may have a clean run. However, if you scroll up to check the output lines, you may see this line: configure: WARNING: MOC not found; bitcoin-qt frontend will not be built. If you want the frontend, run:
安装qt图标界面库
 
 
sudo apt-get install libqt4-core libqt4-gui libqt4-dev
Then when you run configure again, you should see checking for moc-qt4… /usr/bin/moc-qt4.

Now, everything is ready.

一切OK,接下来可以开始编译了。 
 
 
make
The compilation took like 5 min. Then install the compiled binary。
差不多五分钟过后,然后开始安装运行程序。
 
 
make install
Now just run the following to bring up the bitcoin frontend, yeah~~~
接下来就可以运行了。
 
 
bitcoin-qt
To start mining, go to Help > Debug Window > Console and type in setgenerate true to turn it on. Type setgenerate false to stop. My machine became really hot after a while, probably coz my CPU was struggling with all the complex computations. I read that some people bought a separate GPU card for better performance, something to consider.

It’s worth noting that nowadays it’s very hard to efficiently mine bitcoins alone without dedicated software and hardware. Often miners form a pool (or a group) to speed up the process and share the profit. Read more at:

https://en.bitcoin.it/wiki/Pooled_mining
https://en.bitcoin.it/wiki/Comparison_of_mining_pools


经过上文中的方法我第一次编译通过了,但是后来发现运行时还是有错,再试了一下发现没有bitcoin-qt。回到源码的目录,运行了一下./configure发现发了google的protobuff工具,所以在网上下载了一个。安装上之后发现还是出现同样的make check错误无法编译bitcoin-qt,马上感觉应该是protobuff的环境变量没有加上,然后在~/.bashrc中加上了PROTOBUF_HOME的环境变量,这次再make一下,觉得这次应该没有什么问题了吧,但编译到一半突然出现了一个致命错误:
致命错误: paymentrequest.pb.h:没有那个文件或目录 编译中断。
在网上找到了答案,因为使用的是CXX编译的,网上说这个要用g++,但g++和gcc我都是装了的。最后的解决方法是:
输入sudo apt-get install gcc-multilib 即可
接下来再编译通过了,希望这一次不要出问题,然后我再make install一下试试。
哈哈哈。。。。
运行bitcoin-qt后出现了下边的画面:

 下一步的工作,就是学着修改源码了。有兴趣的同学大家一起来改变世界吧。
另一个,就是客端是有RPC的网络接口的,可以在配置文件中进行设置,这样就要以使用json的方式访问你的客户端了,这方面我正在研究,回头再补充。

猜你喜欢

转载自blog.csdn.net/yhc166188/article/details/80713622