交叉編譯Windows Aria2
編譯環境 Ubuntu 16.0.4
首先安裝相關依賴
apt-get install -y gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 libgnutls28-dev nettle-dev libgmp-dev libssh2-1-dev libc-ares-dev libxml2-dev zlib1g-dev libsqlite3-dev pkg-config libcppunit-dev autoconf automake autotools-dev autopoint libtool git gcc g++ libxml2-dev make quilt libcurl4-openssl-dev libevent-dev ca-certificates libssl-dev build-essential intltool libgcrypt-dev libssl-dev python-pip
pip install --upgrade pip
pip install sphinx
配置函式庫
安裝 zlib c-ares expat sqlite3 openSSL libssh2 並進行相關配置
這裡使用腳本進行安裝
vim aria2-x86_64-w64-mingw-build-libs
貼上以下內容
#!/bin/bash
# In this configuration, the following dependent libraries are compiled:
#
# * zlib
# * c-ares
# * expat
# * sqlite3
# * openSSL
# * libssh2
#IMPORTANT: Require install gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64
#CHECK TOOL FOR DOWNLOAD
aria2c --help > /dev/null
if [ "$?" -eq 0 ] ; then
DOWNLOADER="aria2c --check-certificate=false"
else
DOWNLOADER="wget -c"
fi
## DEPENDENCES ##
ZLIB=http://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz
OPENSSL=http://www.openssl.org/source/openssl-1.0.2o.tar.gz
EXPAT=https://sourceforge.net/projects/expat/files/expat/2.2.0/expat-2.2.0.tar.bz2
SQLITE3=http://www.sqlite.org/2018/sqlite-autoconf-3230100.tar.gz
C_ARES=http://c-ares.haxx.se/download/c-ares-1.14.0.tar.gz
SSH2=https://www.libssh2.org/download/libssh2-1.7.0.tar.gz
## CONFIG ##
BUILD_DIRECTORY=/tmp/
HOST=x86_64-w64-mingw32
PREFIX=/usr/x86_64-w64-mingw32
## BUILD ##
cd $BUILD_DIRECTORY
#
# zlib build
$DOWNLOADER $ZLIB
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
CC=$HOST-gcc CXX=$HOST-g++ AR=$HOST-ar RANLIB=$HOST-ranlib ./configure --prefix=$PREFIX --static
make
make install
#
# expat build
cd ..
$DOWNLOADER $EXPAT
tar jxvf expat-2.2.0.tar.bz2
cd expat-2.2.0/
CC=$HOST-gcc CXX=$HOST-g++ AR=$HOST-ar RANLIB=$HOST-ranlib ./configure --prefix=$PREFIX --host=$HOST --enable-static --enable-shared
make
make install
#
# c-ares build
cd ..
$DOWNLOADER $C_ARES
tar zxvf c-ares-1.14.0.tar.gz
cd c-ares-1.14.0/
CC=$HOST-gcc CXX=$HOST-g++ AR=$HOST-ar RANLIB=$HOST-ranlib ./configure --prefix=$PREFIX --host=$HOST --enable-static --disable-shared
make
make install
#
# Openssl build
cd ..
$DOWNLOADER $OPENSSL
tar zxvf openssl-1.0.2o.tar.gz
cd openssl-1.0.2o/
./Configure mingw64 --cross-compile-prefix=$HOST- --prefix=$PREFIX shared
make
make install
#
# sqlite3
cd ..
$DOWNLOADER $SQLITE3
tar zxvf sqlite-autoconf-3230100.tar.gz
cd sqlite-autoconf-3230100/
CC=$HOST-gcc CXX=$HOST-g++ AR=$HOST-ar RANLIB=$HOST-ranlib ./configure --prefix=$PREFIX --host=$HOST --enable-static --enable-shared
make
make install
#
# libssh2
cd ..
$DOWNLOADER $SSH2
tar zxvf libssh2-1.7.0.tar.gz
cd libssh2-1.7.0/
rm -rf $PREFIX/lib/pkgconfig/libssh2.pc
CC=$HOST-gcc CXX=$HOST-g++ AR=$HOST-ar RANLIB=$HOST-ranlib ./configure --prefix=$PREFIX --host=$HOST --enable-static --disable-shared
make
make install
#
#cleaning
cd ..
rm -rf c-ares*
rm -rf sqlite-autoconf*
rm -rf zlib-*
rm -rf expat-*
rm -rf openssl-*
rm -rf libssh2-*
#
echo "finished!"
貼上後儲存並離開
賦予執行權限
chmod +x aria2-x86_64-w64-mingw-build-libs
執行腳本
./aria2-x86_64-w64-mingw-build-libs
這裡要等帶一段時間
完成後,下載aria2原碼
wget https://github.com/aria2/aria2/releases/download/release-1.34.0/aria2-1.34.0.tar.gz
解壓縮
tar -zxvf aria2-1.34.0.tar.gz
切換至該目錄
cd aria2-1.34.0
修改Aria2為128線程
這裡使用腳本來進行修改
vim replace.sh
貼上以下內容
#!/bin/bash
sed -i 's/"1", 1, 16/"128", 1, -1/g' ./src/OptionHandlerFactory.cc
sed -i 's/"20M", 1_m, 1_g/"4K", 1_k, 1_g/g' ./src/OptionHandlerFactory.cc
sed -i 's/PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "60", 1, 600/PREF_CONNECT_TIMEOUT, TEXT_CONNECT_TIMEOUT, "30", 1, 600/g' ./src/OptionHandlerFactory.cc
sed -i 's/PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_m, 1_g/PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "4k", 1_k, 1_g/g' ./src/OptionHandlerFactory.cc
sed -i 's/new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "0", 0, 600/new NumberOptionHandler(PREF_RETRY_WAIT, TEXT_RETRY_WAIT, "2", 0, 600/g' ./src/OptionHandlerFactory.cc
sed -i 's/new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "5", 1, -1,/new NumberOptionHandler(PREF_SPLIT, TEXT_SPLIT, "8", 1, -1,/g' ./src/OptionHandlerFactory.cc
賦予執行權限
chmod +x replace.sh
執行腳本
sh replace.sh
配置Aria2的編譯環境
完成後,配置Aria2的編譯環境
這裡使用腳本來進行配置
vim aria2-x86_64-w64-mingw-config
貼上以下內容
#!/bin/bash
# In this configuration, the following dependent libraries are used:
#
# * zlib
# * c-ares
# * expat
# * sqlite3
# * openSSL
# * libssh2
HOST=x86_64-w64-mingw32
PREFIX=/usr/x86_64-w64-mingw32
./configure \
--host=$HOST \
--prefix=$PREFIX \
--without-included-gettext \
--disable-nls \
--with-libcares \
--without-gnutls \
--without-wintls \
--with-openssl \
--with-sqlite3 \
--without-libxml2 \
--with-libexpat \
--with-libz \
--without-libgmp \
--with-libssh2 \
--without-libgcrypt \
--without-libnettle \
--with-cppunit-prefix=$PREFIX \
ARIA2_STATIC=yes \
CPPFLAGS="-I$PREFIX/include" \
LDFLAGS="-L$PREFIX/lib" \
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
儲存並離開
賦予執行權限
chmod +x aria2-x86_64-w64-mingw-config
執行配置編譯環境腳本 [ 注意!!!這裡是在aria2-1.34.0該目錄底下進行動作的 ]
./aria2-x86_64-w64-mingw-config
編譯
過程沒出錯的話就可以開始編譯了
make
如果想要加快編譯速度的話
可以使用
make -j 4 #使用4線程進行編譯的意思,如果不帶數字的話,代表不限制線程數,ps:小心翻車
編譯完成後產生的aria2c.exe會在aria2-1.34.0/src目錄底下
複製出來
cp aria2-1.34.0/src/aria2c.exe /root
去除aria2c.exe的連接符
切換至/root
去除aria2c.exe的連接符,能幫它減肥
strip -s aria2c.exe
到這裡就完成啦
4 comments
请问您尝试过编译lib和dll么?exe我按照官方教程已经成功了,然而我需要的是dll和lib,请问,你可以给我一点经验么
编译完之后确实可以在 Windows 上下载了,但是只要是 HTTPS 的网站都会提示 SSL/TLS handshake failure: self signed certificate in certificate chain ,请问如何解决?
感謝WIJTB這麼詳細的交叉編譯Windows Aria2
網路上很多文章都寫的很簡略新手常常還是編譯失敗
因為我自己在windows下沒有用到openssl
所以我配置函式庫時拿掉openssl
並改成使用winsows用的WinTLS
把aria2-x86_64-w64-mingw-config裡面的部份這兩個改成
--with-wintls \
--without-openssl \
編譯成功下載https的檔案也一切正常
下面是我的PowerShell輸出過程給你參考
Windows PowerShell
著作權 (C) Microsoft Corporation. 著作權所有,並保留一切權利。
PS C:\Users\charles1018> aria2c -v
aria2 version 1.34.0
Copyright (C) 2006, 2017 Tatsuhiro Tsujikawa
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
** Configuration **
Enabled Features: Async DNS, BitTorrent, Firefox3 Cookie, GZip, HTTPS, Message Digest, Metalink, XML-RPC, SFTP
Hash Algorithms: sha-1, sha-224, sha-256, sha-384, sha-512, md5, adler32
Libraries: zlib/1.2.11 expat/2.2.6 sqlite3/3.26.0 c-ares/1.15.0 libssh2/1.8.0
Compiler: mingw-w64 5.0 (alpha) / gcc 7.3-win32 20180312
built by x86_64-pc-linux-gnu
targeting x86_64-w64-mingw32
on Jan 19 2019 13:08:24
System: Windows 6.2 (x86_64) (6.2)
Report bugs to https://github.com/aria2/aria2/issues
Visit https://aria2.github.io/
PS C:\Users\charles1018> aria2c -x 128 https://speed.hetzner.de/100MB.bin
01/19 13:38:37 [NOTICE] Downloading 1 item(s)
[#583927 0B/0B CN:1 DL:0B]
01/19 13:38:39 [NOTICE] Allocating disk space. Use --file-allocation=none to disable it. See --file-allocation option in man page for more details.
[#583927 99MiB/100MiB(99%) CN:8 DL:2.9MiB]
01/19 13:39:10 [NOTICE] Download complete: C:/Users/charles1018/100MB.bin
Download Results:
gid |stat|avg speed |path/URI
======+====+===========+=======================================================
583927|OK | 3.2MiB/s|C:/Users/charles1018/100MB.bin
Status Legend:
(OK):download completed.
您有配置aria2的ssl證書嗎?