Thursday, September 20, 2012

Compile Aria2 1.15.2 with MinGW

Aria2 is a command-line download utility. It can be used to download files quickly from http(s), ftp, bittorrent, magnet and metalink locations. I prefer this handy tool over other programs, such as Free Download Manager and Frostwire because it's lean, fast and full of features. It took me a couple of days to compile Aria2 with all the features available. The following step-by-step guide will help you build your own aria2 program (aria2c.exe) the way I did.







  1. Install MinGW

    Follow one of the following guides to install MingW:




  2. POSIX Threads

    Download the source for Pthreads library (pthreads-w32-2-9-1-release.tar.gz) and compile it like this:


    make clean GC-static
    cp pthread.h semaphore.h sched.h /mingw/include/
    cp libpthreadGC2.a /mingw/lib/libpthread.a


  3. zlib

    Zlib is needed by the OpenSSL library below. Download the zlib source and compile it like this:


    make -f win32/Makefile.gcc
    make -f win32/Makefile.gcc install BINARY_PATH=/mingw/bin INCLUDE_PATH=/mingw/include LIBRARY_PATH=/mingw/lib


  4. OpenSSL

    Aria2 requires either GnuTLS or OpenSSL for secure transfers. In this guide, OpenSSL is chosen over GnuTLS. Use 7-zip to unpack the tarball because it contains symbolic links.


    ./Configure -DHAVE_STRUCT_TIMESPEC -DPTW32_STATIC_LIB -L/mingw/lib -lz -lpthread -lws2_32 --prefix=/mingw threads zlib mingw
    make
    make install


  5. Expat


    Aria2 can use either LibXML2 or Expat for XML parsing. In this guide, Expat will be used. Download the expat source and compile expat like this:


    ./configure --build=i686-w64-mingw32 --prefix=/mingw --disable-shared --enable-static
    make
    make install


  6. C-Ares


    C-Ares is a C library that performs DNS requests and resolves DNS names asynchronously. Download the C-ares source from c-ares.haxx.se and unpack it. Then, compile C-Ares as follows:


    ./configure --build=i686-w64-mingw32 --prefix=/mingw --disable-shared CPPFLAGS='-I/mingw/include -DCARES_STATICLIB'
    make
    make install


  7. SQLite 3


    Download the SQLite source (sqlite-amalgamation-3071300.zip) and build SQLite 3:


    gcc -O2 -DNDEBUG=1 -DTHREADSAFE=1 -c *.c
    ar ru /mingw/lib/libsqlite3.a sqlite3.o
    cp -iv *.h /mingw/include

    Create sqlite3.pc and put it in /mingw/lib/pkgconfig.


    prefix=/mingw
    exec_prefix=${prefix}
    libdir=${exec_prefix}/lib
    includedir=${prefix}/include

    Name: SQLite
    Description: SQL database engine
    Version: 3.5

    Libs: -L${libdir} -lsqlite3
    Cflags: -I${includedir}


  8. aria2c


    Finally, we are ready to compile Aria2. Download the Aria2 source from aria2.sf.net and unpack the source. Then, configure aria2 as follows:


    ./configure --build=i686-w64-mingw32 --prefix=/mingw --enable-threads=posix --with-ca-bundle=ca-bundle.crt --disable-nls LIBS='-lpthread -lws2_32 -lcares -lz' CPPFLAGS='-DPTW32_STATIC_LIB -DCARES_STATICLIB'


    aria2_config

    Then, issue the following commands to compile Aria2:


    make
    make install


  9. Optionally, strip and compress the executable aria2c.exe.

    strip aria2c.exe
    upx --best --strip-relocs=0 aria2c.exe



To download my Windows builds of aria2, go here.



Aria2c Usage


aria2c --file-allocation=prealloc ftp://192.168.1.64/pardus.iso

If aria2 aborts a download due to a connection error, you can resume the download any time using aria2c like this:


aria2c -c ftp://192.168.1.64/pardus.iso

To download files from URL's written in a file urls.txt to a folder Downloads, run aria2 as follows. The urls.txt should contain one download per line with URL's seperated by a tab:


aria2c -i urls.txt -d Downloads

2 comments:

  1. Thanks for the detailed instructions!
    Have you seen this error before?

    In file included from SocketCore.cc:35:
    SocketCore.h:363: error: expected ',' or '...' before 'struct'
    SocketCore.cc: In function 'SOCKET aria2::bindTo(const char*, uint16_t, int, int, int, std::string&)':

    Aria2 1.8.0, TDM-2 4.4.1

    ReplyDelete
  2. I have installed aria2c step by step as above, but I found an error in enable-bittorent and openssl for windows.

    What is wrong? help me, please!
    awaited an answer from you. thanks before .....

    ReplyDelete

About This Blog

KBlog logo This blog is about current events and issues concerning general population. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger