In the windows environment compiler to build Bitcoin

Recent plan under study Bitcoin source code, but found that was compiled to run under linux source code under normal circumstances this, but my machine is the windows.

How to do it?

Initially intended to use mingw and cygwin mess things look, try a long time after the discovery does not work, the job must go to linux environment.

In order to use linux environment under the windows, was originally intended to use the virtual machine, and later remembered already under win10 linux support the (WSL), so I plan to try with WSL, I did not think really successful.

So write this article, record the environment building process, in order to avoid future recurrence of similar words will demand detours.

Install and configure WSL

Before you begin to determine what version of Windows is not Windows10, and then recommends updating to the latest version.
Open  in the Microsoft Store  , search for  Linux  there will be three results  Ubuntu  ,  openSUSE Leap42  ,  SUSE Linux Enterprise Srever

 


Because it is based Pick daily  Ubuntu , with exemplary Ubuntu (WSL where Ubuntu comes git, vim, ssh other commonly used software, the other not used unclear) as
after the installation is complete fool (not even the next step ), a notification will pop open directly on the line, if there is no notice may be found to start in just installed  Ubuntu  open on the line

 


However, this time will find that there is no prompt can not open WSL, the need to start retry

 

 

 


Go to Control Panel \ All Control Panel Items \ Programs and Features, select Enable Windows features on or off

 

 

 


Found for Linux and Windows subsystem check, and then select OK Restart Now

 

 

 

重启之后再次打开 Ubuntu 就可以使用了,根据提示输入用户名,两次输入密码就可以看见熟悉的命令行

 

然后熟悉的套路,先设置root用户

sudo passwd root

 

 

su root

然后输入root用户的密码即可,接着更换 apt 的数据源

cd /etc/apt  #进入配置文件所在目录
cp sources.list sources.list.bak  #备份配置文件
vim sources.list  #编辑配置文件

将下面的配置覆盖 sources.list 中的配置

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

于是我就想,既然这是安装在Windows上的子系统,那是不是应该有着类似于共享文件夹的东西,于是找到了这么一个文件夹

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

这个就是 Ubuntu WSL版的根目录,接着到 *etc\apt* 下找到 sources.list 用之前贴的配置文件覆盖即可.接着更新数据源

sudo apt-get update  #更新源  
sudo apt-get upgrade  #更新软件 

安装并编译比特币源码

首先,我们去拿比特币源码

git clone https://github.com/bitcoin/bitcoin.git

然后,执行以下命令,安装编译所需的组件

sudo apt-get install make

sudo apt-get install gcc

sudo apt-get install g++

sudo apt-get install libdb-dev

sudo apt-get install libdb++-dev

sudo apt-get install libdb5.1++-dev

sudo apt-get install libboost-dev

sudo apt-get install libboost-all-dev

sudo apt-get install zlib1g-dev

sudo apt-get install libssl-dev

sudo apt-get install build-essential

sudo apt-get install libminiupnpc-dev

sudo apt-get install autoconf

sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler

sudo apt-get install libqrencode-dev libminiupnpc-dev

第三步,安装berkeley-db(伯克利 数据库):

Berkeley DB是一个开源的文件数据库,介于关系数据库与内存数据库之间,使用方式与内存数据库类似,它提供的是一系列直接访问数据库的函数,而不是像关系数据库那样需要网络通讯、SQL解析等步骤。

在bitcoin目录下建立文件夹db4:

cd bitcoin

mkdir db4

然后下载berkeley-db安装包:

wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz' 

我安装这个版本的berkeley挺顺利的。如果不顺利,可以尝试下载

wget 'http://download.oracle.com/berkeley-db/db-6.2.32.NC.gz'

这个版本的数据库。

接下来就是解压和编译:

tar -xzvf db-4.8.30.NC.tar.gz

cd db-4.8.30.NC/build_unix/

../dist/configure --enable-cxx --disable-shared --with-pic --prefix=/home/theusername/bitcoin/db4/

make install

最后,编译比特币主代码:

进入代码主目录

./autogen.sh

./configure LDFLAGS="-L/home/theusername/bitcoin/db4/lib/" CPPFLAGS="-I/home/theusername/bitcoin/db4/include/"

make

sudo make install

验证是否安装成功:

那怎样证明安装成功了呢。我们通过以下两个命令行进行验证:

$ which bitcoind

/usr/local/bin/bitcoind

$ which bitcoin-cli

/usr/local/bin/bitcoin-cli

结果正常输出了。终于完成了进入比特币源码世界的第一步了。

 

本博文借鉴资料:

https://www.jianshu.com/p/0d3a32a0a973
https://www.jianshu.com/p/6b02948b3d37

Guess you like

Origin www.cnblogs.com/lsm19870508/p/11468764.html