Build shadowsocks-libev on Windows with MinGW-w64

Shadowsocks is a cross-platform lightweight and highly efficient secure proxy application originally developed by @clowwindy and currently maintained by multiple developers. Shadowsocks was developed with python but has been ported to various programming languages. Out of many versions, shadowsocks-libev is written in C and is well maintained. The server version is working incredibly fast, and I think the client version will also work well. But there are few articles introducing the ways to build shadowsocks-libev on Windows. The official documentation only lists some commands. With the help of the developer, I am able to build it and run it on Windows platform.

Environment setup

  1. Download git from https://git-scm.com/download/win.

  2. Install git and make sure the git command path is added to the Windows “path” variable.

  3. Download msys2 installer from https://msys2.github.io/.

  4. Install msys2 by following the wizard on the website.

Install toolchain

  1. Determine the architecture of your target app. You can choose to build 32-bit or 64-bit depending on your needs. Normally 32-bit will do the job pretty well unless you are obsessed with building the 64-bit app for 64-bit system. This guide will build the 32-bit app.

  2. Launch the “MinGW-w64 Win32 Shell” from the Start Menu. The name sounds a bit confusing, but it is what we want to open.

  3. Execute the following command to install the toolchain

pacman -S mingw-w64-i686-toolchain tar perl make openssl asciidoc xmlto
  1. Verify that git is installed correctly by executing
git version

Get code

  1. Checkout shadowsocks-libev from GitHub.
git clone https://github.com/shadowsocks/shadowsocks-libev.git
  1. Checkout specific version. At the time of writing this article, the most current version is v2.4.5.
cd shadowsocks-libev
git checkout v2.4.5

Build shadowsocks-libev

  1. Configure
./configure --prefix="$HOME/ss"
  1. Build
make && make install
  1. After successfully building the app, you can find the binary in $HOME/ss/bin directory. There should be two executables. ss-local.exe is the client and ss-tunnel.exe is for another usage. Copy these two files to c:/bin/shadowsocks.

  2. Copy the following files from your msys2 installation folder (under your msys2 installation path/mingw32/bin) to the same folder as your ss-local.exe and ss-tunnel.exe (c:/bin/shadowsocks)

libeay32.dll
libgcc_s_dw2-1.dll
libssp-0.dll
libwinpthread-1.dll
  1. Create a config.json file with the correct format. Refer to https://github.com/shadowsocks/shadowsocks-libev/blob/master/debian/config.json as an example.

  2. Open a native Windows CMD window, and navigate to c:/bin/shadowsocks directory.

  3. Start ss-local.exe by executing the following command.

ss-local.exe -c config.json
  1. Depending on your server settings, if you have enabled One-time authentication in your server, you can start ss-local.exe like this instead.
ss-local.exe -A -c config.json
  1. Shadowsocks-libev has started. You can now change your system or browser proxy configuration to point to the shadowsocks-libev client.

Auto start

  1. We can use the built-in Windows task scheduler to automatically start the shadowsocks-libev.

  2. Close any shadowsocks-libev instances before starting. You can use the task manager to kill the process.

  3. Open a native Windows CMD window as an administrator, and then execute the following command.

schtasks /create /ru "SYSTEM" /sc onstart /tn shadowsocks /tr "C:\bin\shadowsocks\ss-local.exe -c C:\bin\shadowsocks\config.json" /f
  1. Depending on your server settings, if you have enabled One-time authentication in your server, you can issue the following command instead.
schtasks /create /ru "SYSTEM" /sc onstart /tn shadowsocks /tr "C:\bin\shadowsocks\ss-local.exe -A -c C:\bin\shadowsocks\config.json" /f
  1. Issue the following command to start shadowsocks-libev. You need to run as an administrator.
schtasks /run /tn shadowsocks
  1. Issue the following command to stop shadowsocks-libev. You need to run as an administrator.
schtasks /end /tn shadowsocks
  1. If you want to delete the task, you can issue the following command. You need to run as an administrator.
schtasks /delete /tn shadowsocks
  1. If you don’t want to start shadowsocks as a system account or you don’t want to run shadowsocks as an administrator, you can go to the Task Scheduler to modify the task settings. Change the account to your own account and select “Hidden” and “Run whether user is logged on or not”.

task-config

Congratulations, you now have successfully built the shadowsocks-libev on Windows.

2 thoughts on “Build shadowsocks-libev on Windows with MinGW-w64”

Leave a Reply

Your email address will not be published. Required fields are marked *