【比特币】自己动手编译比特币客户端

本帖只谈技术实现,首先我们自己来编译一个比特币客户端吧, 技术讨论QQ群,161928517欢迎大家入伙(注明:csdn)


如果看文此文您觉得对您有帮助,欢迎捐赠博主:

1MMkfgNEw96B83DQq3DFtL9WxcTN7keFPG



2014.7.18更新:

静态编译的第三方依赖和MINGW64工具链以及v0.9.1的官方源代码在github上:

https://github.com/imharrywu/betcoin

本文遇到的问题大部分是使用动态库构建的时候遇到的,仅仅作为一个备份,大家可以直接迁出上面的代码或者直接跳到本文的最后看《自动脚本》

不带任何qt-style风格的qt界面库构建出来的比特币satoshi客户端

【比特币】自己动手编译比特币客户端_第1张图片

=======================================================================================================================





先看一下最后编出来的带qt前端的客户端版本截图,会有测试版本提示 (使用tag的源代码编译正式版本)

(建议:备份您之前安装的%APPDATA%bitcoin目录)。

【比特币】自己动手编译比特币客户端_第2张图片


参考github上的描述文件

https://github.com/bitcoin/bitcoin/blob/master/doc/build-msw.md


1) 签出代码

GitHub上的官方源代码


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

也可以从csdn的code上签出本文的整个项目组

git clone git://code.csdn.net/wuzh1230/bitcoin.git

提示:

<1>已经包含了预编译的依赖库在3rd目录下;

<2>已经包含了ming32工具链,请修改msys/1.0/etc/fstab

<3>文章遇到的问题大多是使用动态库构造的时候遇到的,建议大家用--enable-static构造所有的依赖,直接跳到最后一节《自动脚本》


2) 下载依赖包

Libraries you need to download separately and build:

name            default path               download
----------------------------------------------------
OpenSSL         \openssl-1.0.1c-mgw        http://www.openssl.org/source/
Berkeley DB     \db-4.8.30.NC-mgw          http://www.oracle.com/technology/software/products/berkeley-db/index.html
Boost           \boost-1.50.0-mgw          http://www.boost.org/users/download/
miniupnpc       \miniupnpc-1.6-mgw         http://miniupnp.tuxfamily.org/files/


3) 编译依赖包

3.1) OpenSSL

cd /c/openssl-1.0.1c-mgw
./config
make
未发现问题,如有任何问题,欢迎讨论。








3.2) Berkeley DB

cd /c/db-4.8.30.NC-mgw/build_unix
sh ../dist/configure --enable-mingw --enable-cxx --disable-replication
make
注意:卸载mingw安装包中pthread组件,否则,BDB会尝试构建repmgr模块(repmgr_posix.c需要posix支持,mingw32不支持)。
注意:2014.4.19更新,在用i686-w64-ming32编译的时候发现,repmgr模块还依赖iostream标准头文件,可以考虑直接--disable-replication,而不必删除编译器的pthread组件。sh ../dist/configure --enable-mingw --enable-cxx --disable-replication 

3.3) Boost

downloaded boost jam 3.1.18
cd \boost-1.50.0-mgw
(0) 修改一个类的dll导出修饰 boost\program_options\detail\config_file.hpp, 参考最好的注意事项
(1) 准备bjam.exe,考虑到boost对mingw的支持不是很好,折中的办法是用vc++的命令行构建一个bjam(比如:bootstrap.bat vc9);然后用这个b2.exe构建mingw版本的boost。
(2)执行 b2 --prefix=/d/workspace/temp install toolset=gcc link=shared variant=release runtime-link=shared threading=multi --without-mpi --without-python --without-wave --without-graph --without-graph_parallel

3.4) MiniUPnPc

cd /c/miniupnpc-1.6-mgw
make -f Makefile.mingw
mkdir miniupnpc
cp *.h miniupnpc/
(1)修改一个miniupnpc.def里面的LIBRARY指定的库名称为空的问题;
(2)修改一个Makefile.mingw的del命令;
(3)添加-Wl,前缀给-enable-stdcall-fixup选项
(4)可以考虑使用最新的版本,1.9.20140401版本,已经修复了上面提到的3个问题

3.5) libpng

        编译png编码库( libpng下载地址)支持二维码生成

        

./configure --prefix=/usr/local/libpng-1.6.10 && make && make install

3.6) qrencode

        二维码编码库( 下载QREncode地址),需要png和pkg-config支持,下载一个lite版本解压到mingw目录下


./configure --prefix=/usr/local/qrencode-3.4.3 png_CFLAGS="-I/usr/local/libpng-1.6.10/include" png_LIBS="-L/usr/local/libpng-1.6.10/lib -lpng16" && make && make install

3.7) zlib

$ make -f win32/Makefile.gcc install \
                SHARED_MODE=1 \
                DESTDIR=/usr/local/zlib-1.2.8/ \
                BINARY_PATH=bin \
                INCLUDE_PATH=include \
                LIBRARY_PATH=lib

3.8) protobuf

$ ./configure --prefix=/usr/local/protobuf-2.5.0 \
            CPPFLAGS=-I/usr/local/zlib-1.2.8/include\
            LDFLAGS=-L/usr/local/zlib-1.2.8/lib \
            LIBS=-lz


4) 编译bitcoin客户端

编译脚本samplebuild.sh的代码,请修改DEPEND_HOME变量


export DEPEND_HOME=/d/cifs/try/buildbtc/csdn/bitcoin/3rd
./configure \
--disable-tests \
--with-boost="${DEPEND_HOME}/boost-1.50.0-mgw" \
--with-miniupnpc=yes \
CPPFLAGS="-D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -w -g -O0 -I${DEPEND_HOME}/db-4.8.30.NC-mgw/include -I${DEPEND_HOME}/miniupnpc-1.6-mgw/include -I${DEPEND_HOME}/openssl-1.0.1c-mgw/include -I${DEPEND_HOME}/boost-1.50.0-mgw/include/boost-1_50" \
LDFLAGS="-L${DEPEND_HOME}/db-4.8.30.NC-mgw/lib -L${DEPEND_HOME}/miniupnpc-1.6-mgw/lib -L${DEPEND_HOME}/openssl-1.0.1c-mgw/lib" 


4.1) 解决::UnRegisterSleepEx()错误

添加 -D_WIN32_WINNT=0x0601 -DWINVER=0x0601 


4.2) 解决WSAPOLLFD未定义

参考: http://sourceforge.net/p/mingw/bugs/1980/ 

在mingw的winsock2.h里面的第912行附近添加

typedef struct pollfd {
  SOCKET fd;
  short  events;
  short  revents;
} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;

4.3) 解决boost连接问题

参考这个comment

4.3.1) boost_program_options

查看src/m4/ax_boost_program_options.m4的第74行附近:

for libextension in `ls $BOOSTLIBDIR/libboost_program_options*.so* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.so.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.dylib* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.dylib.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.a.*$;\1;'` ; do
修改为:

for libextension in `ls $BOOSTLIBDIR/libboost_program_options*.so* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.so.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.dylib* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.dylib.*$;\1;'` `ls $BOOSTLIBDIR/libboost_program_options*.dll.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_program_options.*\)\.dll\.a.*$;\1;'` ; do

4.3.2) boost_chrono

查看src/m4/ax_boost_chrono.m4的第81行附近:

for libextension in `ls $BOOSTLIBDIR/libboost_chrono*.so* $BOOSTLIBDIR/libboost_chrono*.dylib* $BOOSTLIBDIR/libboost_chrono*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_chrono.*\)\.so.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.a.*$;\1;'` ; do
修改为:

for libextension in `ls $BOOSTLIBDIR/libboost_chrono*.so* $BOOSTLIBDIR/libboost_chrono*.dylib* $BOOSTLIBDIR/libboost_chrono*.dll.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_chrono.*\)\.so.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.dll\.a.*$;\1;'` ; do


4.4) 修复bitcoin构建时的库依赖顺序

libbitcoin_wallet.a依赖于boost的filesystem,但是在src/Makefile.am里面boost_libs设置在libbitcoin_wallet.a之前,但是如果--disable-wallet编译不发现问题。

参考:https://github.com/bitcoin/bitcoin/commit/d696820b45d9b6be1c21a65f2c8ed3b260938cb7


5) 编译核心模块bitcoind

sh autogen.sh && sh samplebuild.sh && make

$ make  
  ...//很多输出
  CXXLD  bitcoind.exe
  CXX    bitcoin-cli.o
  CXXLD  bitcoin-cli.exe
make[3]: Leaving directory `/d/cifs/try/buildbtc/csdn/bitcoin/bitcoin-master/src'
make[2]: Leaving directory `/d/cifs/try/buildbtc/csdn/bitcoin/bitcoin-master/src'
make[1]: Leaving directory `/d/cifs/try/buildbtc/csdn/bitcoin/bitcoin-master/src'
make[1]: Entering directory `/d/cifs/try/buildbtc/csdn/bitcoin/bitcoin-master'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/d/cifs/try/buildbtc/csdn/bitcoin/bitcoin-master'


运行 命令行版本的bitcoin的client,看看帮助提示:

$ ./bitcoin-cli.exe --help
Bitcoin RPC client version v0.8.2-820-gf65dc44-dirty-beta

Usage:
  bitcoin-cli [options] <command> [params]  Send command to Bitcoin server
  bitcoin-cli [options] help                List commands
  bitcoin-cli [options] help <command>      Get help for a command

Options:
  -?                     This help message
  -conf=<file>           Specify configuration file (default: bitcoin.conf)
  -datadir=<dir>         Specify data directory
  -testnet               Use the test network
  -rpcconnect=<ip>       Send commands to node running on <ip> (default: 127.0.0
.1)
  -rpcwait               Wait for RPC server to start
  -rpcuser=<user>        Username for JSON-RPC connections
  -rpcpassword=<pw>      Password for JSON-RPC connections
  -rpcport=<port>        Connect to JSON-RPC on <port> (default: 8332 or testnet
: 18332)

SSL options: (see the Bitcoin Wiki for SSL setup instructions)
  -rpcssl                                  Use OpenSSL (https) for JSON-RPC conn
ections


6) 编译qt前端


如何使用 Ming32构建Qt,参考这个文章。

构建好以后放到3rd目录下备用。

另外下载google的protocbuf工具编译后,放到3rd目录下。

楼主会在git上push所有的需要的lib和工具到3rd目录,包括打包用的 makensis工具。

好了吧,开始配置带qt前端的bticoin。

示例脚本: samplebuild.sh

export MAKENSIS_HOME=/d/cifs/lab/csdn/bitcoin/3rd/nsis-2.46


export PROTOC_BIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/bin
export PROTOC_INC_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/include
export PROTOC_LIB_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/lib


export QT_BIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/bin
export QT_LIB_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/lib
export QT_INC_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/include
export QT_PLUGIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/plugins


export LANG_CODECS_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/plugins/codecs


export DEPEND_HOME=/d/cifs/lab/csdn/bitcoin/3rd


export PATH=$PATH:$MAKENSIS_HOME


./configure \
--disable-tests \
--disable-ipv6 \
--disable-ccache \
--with-boost="${DEPEND_HOME}/boost-1.50.0-mgw" \
--with-miniupnpc=yes \
--with-qt-incdir=${QT_INC_HOME} \
--with-qt-libdir=${QT_LIB_HOME} \
--with-qt-bindir=${QT_BIN_HOME} \
--with-qt-plugindir=${QT_PLUGIN_HOME} \
--with-protoc-bindir=${PROTOC_BIN_HOME} \
CPPFLAGS="-D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -w -g -O0 -I${PROTOC_INC_HOME} -I${DEPEND_HOME}/db-4.8.30.NC-mgw/include -I${DEPEND_HOME}/miniupnpc-1.6-mgw/include -I${DEPEND_HOME}/openssl-1.0.1c-mgw/include -I${DEPEND_HOME}/boost-1.50.0-mgw/include/boost-1_50" \
LDFLAGS="-L${PROTOC_LIB_HOME}-L${LANG_CODECS_HOME} -L${DEPEND_HOME}/db-4.8.30.NC-mgw/lib -L${DEPEND_HOME}/miniupnpc-1.6-mgw/lib -L${DEPEND_HOME}/openssl-1.0.1c-mgw/lib" 

楼主没有打算使用pkg_config。有兴趣的同学可以试试。

如果需要二维码支持,请使用这个 sh samplebuild.sh

export MAKENSIS_HOME=/d/cifs/lab/csdn/bitcoin/3rd/nsis-2.46

export PROTOC_BIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/bin
export PROTOC_INC_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/include
export PROTOC_LIB_HOME=/d/cifs/lab/csdn/bitcoin/3rd/google-protoc-2.5-mgw/lib

export QT_BIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/bin
export QT_LIB_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/lib
export QT_INC_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/include
export QT_PLUGIN_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/plugins

export QR_INC_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qrencode-3.4.3/include
export QR_LIB_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qrencode-3.4.3/lib

export LANG_CODECS_HOME=/d/cifs/lab/csdn/bitcoin/3rd/qt-4.8.5-mingw32-4.8.1/plugins/codecs

export DEPEND_HOME=/d/cifs/lab/csdn/bitcoin/3rd

export PATH=$PATH:$MAKENSIS_HOME

./configure \
--disable-tests \
--disable-ipv6 \
--disable-ccache \
--with-boost="${DEPEND_HOME}/boost-1.50.0-mgw" \
--with-miniupnpc=yes \
--with-qt-incdir=${QT_INC_HOME} \
--with-qt-libdir=${QT_LIB_HOME} \
--with-qt-bindir=${QT_BIN_HOME} \
--with-qt-plugindir=${QT_PLUGIN_HOME} \
--with-protoc-bindir=${PROTOC_BIN_HOME} \
QR_LIBS="-lqrencode" \
CPPFLAGS="-D_WIN32_WINNT=0x0601 -DWINVER=0x0601 -w -g -O0 -I${QR_INC_HOME} -I${PROTOC_INC_HOME} -I${DEPEND_HOME}/db-4.8.30.NC-mgw/include -I${DEPEND_HOME}/miniupnpc-1.6-mgw/include -I${DEPEND_HOME}/openssl-1.0.1c-mgw/include -I${DEPEND_HOME}/boost-1.50.0-mgw/include/boost-1_50" \
LDFLAGS="-L${QR_LIB_HOME} -L${PROTOC_LIB_HOME} -L${LANG_CODECS_HOME} -L${DEPEND_HOME}/db-4.8.30.NC-mgw/lib -L${DEPEND_HOME}/miniupnpc-1.6-mgw/lib -L${DEPEND_HOME}/openssl-1.0.1c-mgw/lib"

然后再来一个 make吧(mingw32-make可能会有CreateProcess失败的提示,linux和windows的路径的问题)

耐心的等待吧,时间还好,比qt4的构建时间短多了。 

运行make deploy可以生成一个安装包,前提是你配置了了makensis打包软件。
并且需要修改一下share/setup.nsi里面的几个linux路径为windows路径, 主要是File指令后面的参数。

【比特币】自己动手编译比特币客户端_第3张图片

安装吧,安装完成以后需要添加几个依赖的dll到安装目录,boost, miniupnpc, berkeley db, protocbuf, 以及mingw的crt等。

【比特币】自己动手编译比特币客户端_第4张图片


Done!


7) 注意事项

1) boost

1) GCC 4.8 warns of ignored attribute in declaration

        Ticket #8725 (closed Bugs: fixed)

2) MINGW构建boost失败

        Ticket #6350: mingw.jam

        boost官方网站表示cygwin和mingw的支持程度是不一样的

3) 导出common_config_file_iterator

        https://github.com/boostorg/program_options/commit/4ae33ce15e5b6345e6eefa19466fdf7cd28a7bbd

2) MiniUPNPc

建议使用最新的1.9版本以上,已经修复以下几个1.6版本的问题:

1) 修改Makefile.mingw

这个是patch文件, 添加del 命令定义,添加-Wl,前缀

需要修改-enable-stdcall-fixup-Wl,-enable-stdcall-fixup:

否则-enable-stdcall-fixup-e会被理解成windows上可执行文件的入口指令,这应该是编译器的一个bug。

谢谢  steking1 同学的提醒

--- D:/cifs/lab/tarballs/Makefile.mingw	周二 四月 19 04:05:38 2011
+++ D:/cifs/lab/tarballs/Makefile.mingw.fixed	周二 二月 25 10:44:20 2014
@@ -8,6 +8,7 @@ CC = gcc
 #CFLAGS = -Wall -g -DDEBUG -D_WIN32_WINNT=0X501
 CFLAGS = -Wall -Os -DNDEBUG -D_WIN32_WINNT=0X501
 LDLIBS = -lws2_32 -liphlpapi
+DEL    = rm -rf
 # -lwsock32
 # -liphlpapi is used for GetBestRoute()
 PYTHON=\utils\python25\python
@@ -23,11 +24,11 @@ init:
 	echo init > init
 
 clean:
-	del upnpc testminixml *.o
-	del dll\*.o
-	del *.exe
-	del miniupnpc.dll
-	del libminiupnpc.a
+	$(DEL) upnpc testminixml *.o
+	$(DEL) dll\*.o
+	$(DEL) *.exe
+	$(DEL) miniupnpc.dll
+	$(DEL) libminiupnpc.a
 
 libminiupnpc.a:	$(OBJS)
 	$(AR) cr $@ $?
@@ -58,10 +59,10 @@ upnpc.o:
 	$(CC) $(CFLAGS) -c -o dll/$@ $<
 
 upnpc-static:	upnpc.o libminiupnpc.a
-	$(CC) -enable-stdcall-fixup -o $@ $^ $(LDLIBS)
+	$(CC) -Wl,-enable-stdcall-fixup -o $@ $^ $(LDLIBS)
 
 upnpc-shared:	dll/upnpc.o miniupnpc.lib
-	$(CC) -enable-stdcall-fixup -o $@ $^ $(LDLIBS)
+	$(CC) -Wl,-enable-stdcall-fixup -o $@ $^ $(LDLIBS)
 
 wingenminiupnpcstrings:	wingenminiupnpcstrings.o
 

2) 从DLL生成导入lib库的时候出错

dllwrap -k --driver-name gcc \
        --def miniupnpc.def \
        --output-def miniupnpc.dll.def \
        --implib miniupnpc.lib -o miniupnpc.dll \
        dll/miniwget.o dll/minixml.o dll/igd_desc_parse.o dll/minisoap.o dll/min
iupnpc.o dll/upnpreplyparse.o dll/upnpcommands.o dll/upnperrors.o dll/connecthos
tport.o dll/portlistingparse.o dll/receivedata.o -lws2_32 -liphlpapi
D:\cifs\mingw32\bin\dlltool: Syntax error in def file miniupnpc.def:5
D:\cifs\mingw32\bin\dlltool: Syntax error in def file miniupnpc.def:5
看看def文件的前面5行, dlltool工具不允许空的library指令,修改一下,在第一行 LIBRARY指令后面添加一下库的名字 miniupnpc:

LIBRARY miniupnpc
; miniupnpc library


EXPORTS
; miniupnpc


3) BerkeleyDB

可以考虑直接禁用repmgr模块 --disable-replication,因为这个模块依赖依赖posix的一些系统api,mingw支持不好。

# Replication can be disabled.
if test "$db_cv_build_replication" = "yes"; then
	AC_DEFINE(HAVE_REPLICATION)
	AH_TEMPLATE(HAVE_REPLICATION,
	    [Define to 1 if building replication support.])
	ADDITIONAL_OBJS="$ADDITIONAL_OBJS \$(REP_OBJS)"

	# If we're building replication and detected POSIX threads, build the
	# replication manager.
	AH_TEMPLATE(HAVE_REPLICATION_THREADS,
	    [Define to 1 if building the Berkeley DB replication framework.])

	if test "$ac_cv_header_pthread_h" = yes; then
		AC_DEFINE(HAVE_REPLICATION_THREADS)

		# Solaris requires the socket and nsl libraries to build the
		# replication manager.  Don't add nsl regardless of the OS,
		# it causes RPC to fail on AIX 4.3.3.
		case "$host_os" in
		solaris*)
			AC_HAVE_LIBRARY(nsl, LIBSO_LIBS="$LIBSO_LIBS -lnsl")
			AC_HAVE_LIBRARY(socket,
			    LIBSO_LIBS="$LIBSO_LIBS -lsocket");;
		esac
		ADDITIONAL_OBJS="$ADDITIONAL_OBJS \$(REPMGR_OBJS)"
	else
		ADDITIONAL_OBJS="$ADDITIONAL_OBJS repmgr_stub${o}"
	fi
else
	ADDITIONAL_OBJS="$ADDITIONAL_OBJS rep_stub${o} repmgr_stub${o}"
fi

4) mingw32在linux交叉编译openssl

http://www.blogcompiler.com/2011/12/21/openssl-for-windows/
http://www.wagner.pp.ru/~vitus/articles/openssl-mingw.html

5) 自动脚本

for windows native building with mingw64, with GUI, used for client
# 1) zlib
make install -f win32/Makefile.gcc \
DESTDIR=/usr/local/zlib-1.2.8/ \
INCLUDE_PATH=include \
LIBRARY_PATH=lib \
BINARY_PATH=bin


# 2) libpng
./configure --prefix=/usr/local/libpng-1.6.9 \
--enable-shared=no \
--enable-static=yes


# 3) qrencode 
./configure --prefix=/usr/local/qrencode-3.4.3 \
--enable-shared=no \
--enable-static=yes \
png_CFLAGS="-I/usr/local/libpng-1.6.9/include" \
png_LIBS="-L/usr/local/libpng-1.6.9/lib -lpng16"


# 4) protobuf
./configure --prefix=/usr/local/protobuf-2.5.0 \
--enable-static=yes \
--enable-shared=no


# 5) BerkeleyDB
cd build_unix && sh ../dist/configure \
--enable-mingw \
--enable-cxx \
--disable-replication


# 6) miniupnpc
make -f Makefile.mingw && mkdir miniupnpc && cp *.h miniupnpc 


# 7) OpenSSL
./config \
no-shared \
no-threads \
no-asm \
no-zlib \
--prefix=/usr/local/ssl \
&& make && make install


# 8) Boost
b2 install --prefix=/usr/local/boost-1.53 \
toolset=gcc \
link=shared \
variant=release \
runtime-link=shared \
threading=multi \
--without-mpi \
--without-python \
--without-wave \
--without-graph \
--without-graph_parallel 

# 9) qt4
configure.exe \
    -I "/usr/local/ssl/include" \
    -L "/usr/local/ssl/lib" \
    -l ssl \
    -l crypto \
    -release \
    -opensource \
    -confirm-license \
    -static \
    -no-ltcg \
    -no-fast \
    -exceptions \
    -accessibility \
    -stl \
    -no-sql-sqlite \
    -no-qt3support \
    -no-opengl \
    -no-openvg \
    -platform win32-g++ \
    -no-system-proxies \
    -qt-zlib \
    -no-gif \
    -qt-libpng \
    -no-libmng \
    -no-libtiff \
    -qt-libjpeg \
    -no-dsp \
    -no-vcproj \
    -no-incredibuild-xge \
    -plugin-manifests \
    -qmake \
    -process -nomake demos -nomake examples -nomake tools \
    -no-rtti \
    -no-mmx \
    -no-3dnow \
    -no-sse \
    -no-sse2 \
    -openssl \
    -no-dbus \
    -no-phonon -no-phonon-backend \
    -no-multimedia -no-audio-backend \
    -no-webkit \
    -no-script -no-scripttools -no-declarative \
    -arch windows \
    -no-style-plastique \
    -no-style-windowsxp -no-style-windowsvista \
    -no-style-cleanlooks -no-style-cde \
    -no-style-motif \
    -no-native-gestures \
    -saveconfig csdnbuild    




# 10)
export DEPEND_HOME=/usr/local
export MAKENSIS_HOME=${DEPEND_HOME}/nsis-2.46
export BDB_INC_HOME=${DEPEND_HOME}/BerkeleyDB.4.8/include
export BDB_LIB_HOME=${DEPEND_HOME}/BerkeleyDB.4.8/lib
export BOOST_TOP_HOME=${DEPEND_HOME}/boost-1.55
export BOOST_INC_HOME=${DEPEND_HOME}/boost-1.55/include/boost-1_55
export BOOST_LIB_HOME=${DEPEND_HOME}/boost-1.55/lib
export PNG_INC_HOME=${DEPEND_HOME}/libpng-1.6.9/include
export PNG_LIB_HOME=${DEPEND_HOME}/libpng-1.6.9/lib
export MINIUPNPC_INC_HOME=${DEPEND_HOME}/miniupnpc-1.9.0/include
export MINIUPNPC_LIB_HOME=${DEPEND_HOME}/miniupnpc-1.9.0/lib
export PROTOC_BIN_HOME=${DEPEND_HOME}/protobuf-2.5.0/bin
export PROTOC_INC_HOME=${DEPEND_HOME}/protobuf-2.5.0/include
export PROTOC_LIB_HOME=${DEPEND_HOME}/protobuf-2.5.0/lib
export QR_INC_HOME=${DEPEND_HOME}/qrencode-3.4.3/include
export QR_LIB_HOME=${DEPEND_HOME}/qrencode-3.4.3/lib
export QT_BIN_HOME=${DEPEND_HOME}/qt-4.8.5-mingw32-4.8.1/bin
export QT_INC_HOME=${DEPEND_HOME}/qt-4.8.5-mingw32-4.8.1/include
export QT_LIB_HOME=${DEPEND_HOME}/qt-4.8.5-mingw32-4.8.1/lib
export QT_PLUGIN_HOME=${DEPEND_HOME}/qt-4.8.5-mingw32-4.8.1/plugins
export QT_CODECS_HOME=${DEPEND_HOME}/qt-4.8.5-mingw32-4.8.1/plugins/codecs
export SSL_INC_HOME=${DEPEND_HOME}/ssl/include
export SSL_LIB_HOME=${DEPEND_HOME}/ssl/lib
export CRYPTO_INC_HOME=${DEPEND_HOME}/ssl/include
export CRYPTO_LIB_HOME=${DEPEND_HOME}/ssl/lib
export ZLIB_INC_HOME=${DEPEND_HOME}/zlib-1.2.8/include
export ZLIB_LIB_HOME=${DEPEND_HOME}/zlib-1.2.8/lib
export PATH=${PATH}:${MAKENSIS_HOME}
./configure \
    --enable-wallet \
    --disable-tests \
    --disable-ipv6 \
    --disable-ccache \
    --with-boost="${BOOST_TOP_HOME}" \
    --with-qrencode=yes \
    --with-miniupnpc=yes \
    --with-protoc-bindir=${PROTOC_BIN_HOME} \
    --with-cli=yes \
    --with-daemon=yes \
    --with-gui=qt4 \
    --with-qt-incdir=${QT_INC_HOME} \
    --with-qt-libdir=${QT_LIB_HOME} \
    --with-qt-bindir=${QT_BIN_HOME} \
    --with-qt-plugindir=${QT_PLUGIN_HOME} \
    CPPFLAGS="-w -g -O0 -I${QR_INC_HOME} -I${PNG_INC_HOME} -I${PROTOC_INC_HOME} -I${SSL_INC_HOME} -I${CRYPTO_INC_HOME} -I${BDB_INC_HOME} -I${MINIUPNPC_INC_HOME} -I${BOOST_INC_HOME} -I${ZLIB_INC_HOME}" \
    LDFLAGS="-L${QR_LIB_HOME} -L${QT_CODECS_HOME} -L${PNG_LIB_HOME} -L${PROTOC_LIB_HOME} -L${SSL_LIB_HOME} -L${CRYPTO_LIB_HOME} -L${BDB_LIB_HOME} -L${MINIUPNPC_LIB_HOME} -L${ZLIB_LIB_HOME}" 


for linux native building with gcc, without gui, used for mining and service.
# 1) Boost
./b2 install --prefix=/root/harrywu/build/3rd/boost toolset=gcc variant=release link=static threading=multi runtime-link=static --without-graph --without-graph_parallel --without-mpi --without-python --without-regex --without-wave


# 2) BerkeleyDB
cd build_unix && ../dist/configure --prefix=/root/harrywu/build/3rd/bdb48 --enable-static=yes --enable-shared=no --enable-cxx --disable-replication --disable-debug


# 3) miniupnpc
make DESTDIR=/root/harrywu/build/3rd/miniupnpc-1.9.0 INSTALLPREFIX= install


# 4) protobuf
./configure --prefix=/root/harrywu/build/3rd/protobuf-2.5.0 --enable-shared=no --enable-static=yes CPPFLAGS=-I/root/harrywu/build/3rd/zlib-1.2.8/include/ LDFLAGS=-L/root/harrywu/build/3rd/zlib-1.2.8/lib LIBS=-lz


# 5) qrencode
./configure --prefix=/root/harrywu/build/3rd/qrencode-3.4.3 --enable-shared=no --enable-static=yes png_CFLAGS=-I/root/harrywu/build/3rd/libpng-1.6.10/ png_LIBS=-L/root/harrywu/build/3rd/libpng-1.6.10/lib/ -lpng16


# 6) ssl
./config no-threads no-shared no-zlib no-asm --prefix=/root/harrywu/build/3rd/ssl


# 7) zlib
./configure --prefix=/root/harrywu/build/3rd/zlib-1.2.8 --static


# 8) libpng
./configure --prefix=/root/harrywu/build/3rd/libpng-1.6.10 --enable-shared=no --enable-static=yes CPPFLAGS=-I/root/harrywu/build/3rd/zlib-1.2.8/include/ LDFLAGS=-L/root/harrywu/build/3rd/zlib-1.2.8/lib LIBS=-lz


# 9) qt missing


# 10) Bitcoin
export DEPEND_HOME=/root/harrywu/build/3rd
export BDB_INC_HOME=${DEPEND_HOME}/BerkeleyDB-4.8.0/include
export BDB_LIB_HOME=${DEPEND_HOME}/BerkeleyDB-4.8.0/lib
export BOOST_TOP_HOME=${DEPEND_HOME}/boost-1.53
export BOOST_INC_HOME=${DEPEND_HOME}/boost-1.53/include/boost-1_55
export BOOST_LIB_HOME=${DEPEND_HOME}/boost-1.53/lib
export PNG_INC_HOME=${DEPEND_HOME}/libpng-1.6.10/include
export PNG_LIB_HOME=${DEPEND_HOME}/libpng-1.6.10/lib
export MINIUPNPC_INC_HOME=${DEPEND_HOME}/miniupnpc-1.9.0/include
export MINIUPNPC_LIB_HOME=${DEPEND_HOME}/miniupnpc-1.9.0/lib
export PROTOC_BIN_HOME=${DEPEND_HOME}/protobuf-2.5.0/bin
export PROTOC_INC_HOME=${DEPEND_HOME}/protobuf-2.5.0/include
export PROTOC_LIB_HOME=${DEPEND_HOME}/protobuf-2.5.0/lib
export QR_INC_HOME=${DEPEND_HOME}/qrencode-3.4.3/include
export QR_LIB_HOME=${DEPEND_HOME}/qrencode-3.4.3/lib
export SSL_INC_HOME=${DEPEND_HOME}/ssl/include
export SSL_LIB_HOME=${DEPEND_HOME}/ssl/lib
export CRYPTO_INC_HOME=${DEPEND_HOME}/ssl/include
export CRYPTO_LIB_HOME=${DEPEND_HOME}/ssl/lib
export ZLIB_INC_HOME=${DEPEND_HOME}/zlib-1.2.8/include
export ZLIB_LIB_HOME=${DEPEND_HOME}/zlib-1.2.8/lib
./configure \
    --enable-wallet \
    --disable-tests \
    --disable-ipv6 \
    --disable-ccache \
    --with-boost="${BOOST_TOP_HOME}" \
    --with-qrencode=yes \
    --with-miniupnpc=yes \
    --with-protoc-bindir=${PROTOC_BIN_HOME} \
    --with-cli=yes \
    --with-daemon=yes \
    --with-gui=no \
    CPPFLAGS="-I${QR_INC_HOME} -I${PNG_INC_HOME} -I${PROTOC_INC_HOME} -I${SSL_INC_HOME} -I${CRYPTO_INC_HOME} -I${BDB_INC_HOME} -I${MINIUPNPC_INC_HOME} -I${BOOST_INC_HOME} -I${ZLIB_INC_HOME}" \
    LDFLAGS="-L${QR_LIB_HOME} -L${PNG_LIB_HOME} -L${PROTOC_LIB_HOME} -L${SSL_LIB_HOME} -L${CRYPTO_LIB_HOME} -L${BDB_LIB_HOME} -L${MINIUPNPC_LIB_HOME} -L${ZLIB_LIB_HOME}" \
LIBS="-lrt -ldl"




你可能感兴趣的:(MinGW,比特币,编译比特币客户端,构建比特币客户端,比特币客户端)