虚拟币钱包开发教程之比特币区块钱包搭建

摘要:虚拟币钱包开发教程之比特币区块钱包搭建

1.准备你的构建系统

1.1安装MinGW(MSYS)shell


http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe

从MinGW安装管理器 - >所有软件包 - > MSYS - >标记以下安装:

From MinGW installation manager -> All packages -> MSYS -> mark the following for installation:

msys-base-bin

... then click on Installation -> Apply changes


确保没有MinGW包检查安装或从以前的安装呈现。只有上面的MSYS包应该被安装。还要确保没有安装msys-gccmsys-w32api软件包。

1.2安装Perl

https://pan.baidu.com/s/1dFhKElj

安装时使用默认值。 无法下载 请联系QQ727721333

1.3安装Python

http://www.python.org/ftp/python/3.3.3/python-3.3.3.amd64.msi

安装时使用默认值。 若无法下载 请联系QQ727721333

1.4从MinGW-builds项目安装工具链:

i686-4.8.2-release-posix-dwarf-rt_v3-rev3.7z下载并解压到C:\\\\\\\\

http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-posix/dwarf/i686-4.8.2-release-posix-矮rt_v3-rev3.7z

1.5设置系统PATH环境变量

确保在PATH环境变量中设置了mingw-builds,MSYS,Perl和Python bin文件夹。在Windows 7上,您的路径应该如下所示:

C:\\\\\\\\MinGW\\\\\\\\msys\\\\\\\\1.0\\\\\\\\bin;C:\\\\\\\\mingw32\\\\\\\\bin;C:\\\\\\\\Python33;C:\\\\\\\\Perl\\\\\\\\site\\\\\\\\bin;C:\\\\\\\\Perl\\\\\\\\bin;%SystemRoot%\\\\\\\\system32;%SystemRoot%;%SystemRoot%\\\\\\\\System32\\\\\\\\Wbem;%SYSTEMROOT%\\\\\\\\System32\\\\\\\\WindowsPowerShell\\\\\\\\v1.0\\\\\\\\

1.6其他检查

C:\\\\\\\\ MinGW \\\\\\\\ bin应该只包含mingw-get.exe。你的gcc -v输出应该是:

$ gcc -v
Using built-in specs.COLLECT_GCC=c:\\\\\\\\mingw32\\\\\\\\bin\\\\\\\\gcc.exeCOLLECT_LTO_WRAPPER=c:/mingw32/bin/../libexec/gcc/i686-w64-mingw32/4.8.2/lto-wrapper.exeTarget: i686-w64-mingw32Configured with: ../../../src/gcc-4.8.2/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw482/i686-482-posix-dwarf-rt_v3-rev3/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw482/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw482/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw482/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw482/prerequisites/i686-w64-mingw32-static --with-cloog=/c/mingw482/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion=\\\\\\\'i686-posix-dwarf-rev3, Built by MinGW-W64 project\\\\\\\' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS=\\\\\\\'-O2 -pipe -I/c/mingw482/i686-482-posix-dwarf-rt_v3-rev3/mingw32/opt/include -I/c/mingw482/prerequisites/i686-zlib-static/include -I/c/mingw482/prerequisites/i686-w64-mingw32-static/include\\\\\\\' CXXFLAGS=\\\\\\\'-O2 -pipe -I/c/mingw482/i686-482-posix-dwarf-rt_v3-rev3/mingw32/opt/include -I/c/mingw482/prerequisites/i686-zlib-static/include -I/c/mingw482/prerequisites/i686-w64-mingw32-static/include\\\\\\\' CPPFLAGS= LDFLAGS=\\\\\\\'-pipe -L/c/mingw482/i686-482-posix-dwarf-rt_v3-rev3/mingw32/opt/lib -L/c/mingw482/prerequisites/i686-zlib-static/lib -L/c/mingw482/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware\\\\\\\'Thread 
model: posixgcc version 4.8.2 (i686-posix-dwarf-rev3, Built by MinGW-W64 project)

2.下载,解包并构建所需的依赖关系

2.1 OpenSSL

http://www.openssl.org/source/openssl-1.0.1g.tar.gz

从MinGW shell(C:\\\\\\\\ MinGW \\\\\\\\ msys \\\\\\\\ 1.0 \\\\\\\\ msys.bat)中解压源文件到C:,重命名文件夹,然后配置并执行:

cd /tar zxvf openssl-1.0.1g.tar.gz -C /c
mv /c/openssl-1.0.1g /c/openssl-1.0.1g-mgw
cd /c/openssl-1.0.1g-mgw
Configure mingwmake

2.2 Berkeley DB

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

我们将使用4.8版来保存二进制钱包的兼容性。从MinGW shell解压缩源文件,配置并进行:

cd /tar zxvf db-4.8.30.NC.tar.gz -C /c
mv /c/db-4.8.30.NC /c/db-4.8.30.NC-mgw
cd /c/db-4.8.30.NC-mgw/build_unix
../dist/configure --disable-replication --enable-mingw --enable-cxx
make

2.3提升

http://sourceforge.net/projects/boost/files/boost/1.55.0/

下载zip或7z压缩包,将Boost解包到C:中,重命名,然后从Windows命令提示符下引导并编译:

cd C:\\\\\\\\
mv C:\\\\\\\\boost_1_55_0 C:\\\\\\\\boost_1_55_0-mgw
cd C:\\\\\\\\boost_1_55_0-mgw
bootstrap.bat mingw
b2 --build-type=complete --with-chrono --with-filesystem --with-program_options --with-system --with-thread toolset=gcc stage

这将编译所需的Boost库,并将它们放到stage文件夹(C:\\\\\\\\ boost_1_55_0 \\\\\\\\ stage)中。注意:确保不要使用tarball,因为unix EOL标记可能会中断批处理文件。

2.4 Miniupnpc

下载http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.9.tar.gz并解压缩到C:,然后从Windows命令提示符下:

cd C:\\\\\\\\
mv C:\\\\\\\\miniupnpc-1.9 C:\\\\\\\\miniupnpc-1.9-mgw
cd C:\\\\\\\\miniupnpc-1.9-mgw
mingw32-make -f Makefile.mingw init upnpc-static
mkdir C:\\\\\\\\miniupnpc-1.9-mgw\\\\\\\\miniupnpc
copy C:\\\\\\\\miniupnpc-1.9-mgw\\\\\\\\*.h C:\\\\\\\\miniupnpc-1.9-mgw\\\\\\\\miniupnpc

2.5 Qrencode

然后下载http://prdownloads.sourceforge.net/libpng/libpng-1.6.9.tar.gz,然后从一个MinGW shell中解开,配置并使之:

cd /tar zxvf libpng-1.6.9.tar.gz -C /c
cd /c/libpng-1.6.9
configure
make

下载并解压C:\\\\\\\\目录下的http://fukuchi.org/works/qrencode/qrencode-3.4.3.tar.gz,然后配置并执行:

cd /tar zxvf qrencode-3.4.3.tar.gz -C /c
mv /c/qrencode-3.4.3 /c/qrencode-3.4.3-mgw
cd /c/qrencode-3.4.3-mgw
LIBS=\\\\\\\"../libpng-1.6.9/.libs/libpng16.a ../../mingw32/i686-w64-mingw32/lib/libz.a\\\\\\\" \\\\\\\\
png_CFLAGS=\\\\\\\"-I../libpng-1.6.9\\\\\\\" 
\\\\\\\\png_LIBS=\\\\\\\"-L../libpng-1.6.9/.libs\\\\\\\" \\\\\\\\
configure --enable-static --disable-shared
make

3.编译对象sharesd

https://github.com/Peershares/Peershares/archive/master.zip下载Peershares master 并解压缩到C:\\\\\\\\

使用文本编辑器,根据您的依赖版本和位置,在C:\\\\\\\\ Peershares-master \\\\\\\\ src \\\\\\\\ makefile.mingw中编辑INCLUDEPATHS,LIBPATHS和LIBS:

INCLUDEPATHS= \\\\\\\\
 -I\\\\\\\"C:\\\\\\\\boost_1_55_0-mgw\\\\\\\" \\\\\\\\
 -I\\\\\\\"C:\\\\\\\\db-4.8.30.NC-mgw\\\\\\\\build_unix\\\\\\\" \\\\\\\\
 -I\\\\\\\"C:\\\\\\\\openssl-1.0.1g-mgw\\\\\\\\include\\\\\\\"LIBPATHS= \\\\\\\\
 -L\\\\\\\"C:\\\\\\\\boost_1_55_0-mgw\\\\\\\\stage\\\\\\\\lib\\\\\\\" \\\\\\\\
 -L\\\\\\\"C:\\\\\\\\db-4.8.30.NC-mgw\\\\\\\\build_unix\\\\\\\" \\\\\\\\
 -L\\\\\\\"C:\\\\\\\\openssl-1.0.1g-mgw\\\\\\\"LIBS= \\\\\\\\
 -l boost_system-mgw48-mt-s-1_55 \\\\\\\\
 -l boost_filesystem-mgw48-mt-s-1_55 \\\\\\\\
 -l boost_program_options-mgw48-mt-s-1_55 \\\\\\\\
 -l boost_thread-mgw48-mt-s-1_55 \\\\\\\\
 -l db_cxx \\\\\\\\
 -l ssl \\\\\\\\
 -l crypto

和...

ifdef USE_UPNP
 INCLUDEPATHS += -I\\\\\\\"C:\\\\\\\\miniupnpc-1.9-mgw\\\\\\\"
 LIBPATHS += -L\\\\\\\"C:\\\\\\\\miniupnpc-1.9-mgw\\\\\\\"
 LIBS += -l miniupnpc -l iphlpapi
 DEFS += -DSTATICLIB -DUSE_UPNP=$(USE_UPNP)
 endif

Upnp支持默认是禁用的。如果你想用UPNP支持集进行编译:

 USE_UPNP:=1

从MinGW shell,编译peersharesd:

cd /c/Peershares-master/src
make -f makefile.mingw
strip peersharesd.exe

4.用Qt 4.8编译peershares-qt.exe

4.1下载并解压Qt 4.8

http://download.qt-project.org/official_releases/qt/4.8/4.8.5/qt-everywhere-opensource-src-4.8.5.zip

假设qt源从Windows命令提示符下解压到C:\\\\\\\\ Qt \\\\\\\\ 4.8.5:

cd C:\\\\\\\\Qt\\\\\\\\4.8.5
configure -release -opensource -confirm-license -static -no-sql-sqlite -no-qt3support -no-opengl -qt-zlib -no-gif -qt-libpng -qt-libmng -no-libtiff -qt-libjpeg -no-dsp -no-vcproj -no-openssl -no-dbus -no-phonon -no-phonon-backend -no-multimedia -no-audio-backend -no-webkit -no-script -no-scripttools -no-declarative -no-declarative-debug -no-style-plastique -no-style-cleanlooks -no-style-motif -no-style-cde -nomake demos -nomake examples
mingw32-make

现在添加“C:\\\\\\\\ Qt \\\\\\\\ 4.8.5 \\\\\\\\ bin;” 到你的系统路径。

4.3编辑C:\\\\\\\\ Peershares-master \\\\\\\\ peershares-qt.pro

用你最喜欢的文本编辑器,添加依赖库的位置:

# Dependency library locations can be customized with:
# BOOST_INCLUDE_PATH, BOOST_LIB_PATH, BDB_INCLUDE_PATH,
# BDB_LIB_PATH, OPENSSL_INCLUDE_PATH and OPENSSL_LIB_PATH respectively
BOOST_LIB_SUFFIX=-mgw48-mt-s-1_55
BOOST_INCLUDE_PATH=C:/boost_1_55_0-mgw
BOOST_LIB_PATH=C:/boost_1_55_0-mgw/stage/lib
BDB_INCLUDE_PATH=C:/db-4.8.30.NC-mgw/build_unix
BDB_LIB_PATH=C:/db-4.8.30.NC-mgw/build_unix
OPENSSL_INCLUDE_PATH=C:/openssl-1.0.1g-mgw/include
OPENSSL_LIB_PATH=C:/openssl-1.0.1g-mgw
MINIUPNPC_INCLUDE_PATH=C:/miniupnpc-1.9-mgw
MINIUPNPC_LIB_PATH=C:/miniupnpc-1.9-mgw
QRENCODE_INCLUDE_PATH=C:/qrencode-3.4.3-mgw
QRENCODE_LIB_PATH=C:/qrencode-3.4.3-mgw/.libs

标记为静态构建:

CONFIG += static

4.5编译peershares-qt.exe

请注意,如果您跳过peersharesd编译,或者如果您清理了源文件夹,则需要在继续之前编译libleveldb.a和libmemenv.a库。如果您编译peersharesd.exe,请跳过此步骤。从MinGW外壳:

cd /C/Peershares-master/src/leveldb
TARGET_OS=NATIVE_WINDOWS make libleveldb.a libmemenv.a

从Windows命令提示配置并使:

cd C:\\\\\\\\Peershares-master\\\\\\\\
qmake \\\\\\\"USE_UPNP=-\\\\\\\" peershares-qt.pro
mingw32-make -f Makefile.Release