Skip to content

kiwix desktop windows.

Matthieu Gautier edited this page Jul 3, 2018 · 6 revisions

Introduction

This is attempt to build kiwix-desktop on Windows. It seems it is pretty complex and, no suspense, I have NOT succeed for now.

However, documenting thing is still good anyway.

DISCLAIMER : This documentation is full of nasty, crappy things, it is ugly and it will give you nightmare. I'm NOT responsible the damages it may inflict you.

I strongly advice to carefully follow this instruction. Every steps and options are important :) However, this documentation is not complete, it is mainly inspired from the notes I've taken. You will have to fill the gaps.

Some general advises:

  • Do not install something else than specified
  • Remove chocolatey packages, cygwin, mingw, python, ...
  • Do not use space in your path. If your user is "FirstName FamillyName", change it !
  • You will need a Windows computer and a Linux one.
  • This have been tested with windows 10. It may work with something else or not.

Information

The dependencies of kiwix-desktop are the following :

kiwix-desktop (C++)
 +- QT (C++)
 +- QTWebEngine (C++)
 +- kiwix-lib (C++)
  +- pugixml (C++)
  +- zlib (C)
  +- lzma (C)
  +- icu4c (C/C++)
  +- libzim (C++)
   +- zlib (C)
   +- lzma (C)
   +- icu4c (C/C++)
   +- xapian (C++)
    +- zlib (C)

As C++ has no standard ABI defined, we need to compile all C++ code with the same compiler. QTWebEngine is compilable only with MSVC on Windows and 64bits only. So, we need to compile all our C++ code with MSVC. Now, the nightmare can start.

  • QT/QTWebengine. A prebuild version exist, compiled with VC 2017
  • pugixml. Pretty easy to compile.
  • zlib. A prebuild version exist but 32 bits...
  • lzma. Yeah, prebuild version 64 bits. It is compiled with mingw64, but as it is C, no problem.
  • icu4c. Microsoft provide a version in Windows, but only the C API (especially because C++ has no standard ABI). However, we are using the C++ API and porting to the C API will be ... difficult. ICU project provide a prebuild lib using VC. ICU also provide a MSVC project to allow recompilation.
  • xapian ... Is build using autotools... Autotools is a nightmare on linux... but it works. On Windows ... [sic]. However xapian folks have start to work on allowing compilation of xapian using MSVC. It is not released yet, but we will use it anyway. (Guys, you are crazy, you've wrote a wrapper around MSVC to transform options in gcc style to MSVC style. Because autotool is crappy). Anyway, all those tools are GNU tools so, we need a Posix env in Windows. We will use Msys2 as xapian doc recommend it.

Our project use meson to compile. meson handles MSVC compiler, so nothing special on this (except few bugs)

As xapian is not yet release, we will need to run maintainer tools, that are available only on Linux, so, keep a linux around. And you will have to copy files from linux to windows, you'd better setup a ssh connection between the two.

Install the tools

Install Git

We will need it to clone repository. Dl https://github.com/git-for-windows/git/releases/download/v2.18.0.windows.1/Git-2.18.0-32-bit.exe and install git in C:\git.

Install Meson on windows

Hopefully, there is a meson installer that embedded python and ninja, lets use it:

Dl https://github.com/mesonbuild/meson/releases/download/0.46.1/meson-0.46.1-64.msi and install meson in C:\meson

Install pkg-config

We will need pkg-config to allow meson to find dependencies. pkg-config needs glib. Hopelly, there is a lite version without glib dependencie:

Install VC

Download Visual Studio from here : https://visualstudio.microsoft.com/fr/thank-you-downloading-visual-studio/?sku=Community&rel=15#

Run the installer and select "Install Visual Studio 2017 Community" (Or equivalent)

Change the install directory to C:\MSVC

Select "C++ Desktop Development" If you are short is disk space, you can unselect everything but (in the right panel):

  • SDK Windows 10 (10.0.17134.0) (or last version)
  • Tools VC++ 2017 version 15.7 v14.14 (last version)
  • Static analytic tools

However, do not select them directly in "Individual Components" (It will not properly setup)

VC will be installed, but the cl compilator will not be in the path by default. You will need to run C:\MSVC\VC\Auxiliary\Build\vcvars64.bat in cmd to have it.

Install msys2

Will will need something that look like a unix system on windows.

DL http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20180531.exe Follow the instruction there (https://www.msys2.org/) to have a up-to-date installation.
Install it in C:\msys64 (the default)

Install Qt

DL the installer here : http://download.qt.io/official_releases/online_installers/qt-unified-windows-x86-online.exe

  • Install Qt in C:\Qt
  • No need to register
  • Install modules QT->Qt 5.11.1->MSVC 2017 64 bits and Qt->Qt 5.11.1->Qt WebEngine

Let's start

Install zlib

The pre-build binary provided by zlib project is a 32bits binary. So we need to compile zlib ourselves.

In a cmd window :

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
[get http://zlib.net/fossils/zlib-1.2.11.tar.gz]
[get https://wrapdb.mesonbuild.com/v1/projects/zlib/1.2.11/3/get_zip]
[Extract both in zlib directory.]
cd zlib
meson . build --prefix C:/Users/<myuser>/dependencies --default-library static --buildtype release
cd build
ninja
ninja install

Install lzma

The pre-build version of libzim is multi arch, we can directly use it.

Install pthread lib

A lot of project use pthread to handle threads. However windows doesn't provide pthread.

We can get a implementation here (https://www.sourceware.org/pthreads-win32/)

The pre-build version of pthread is compiled with MSVC 2010 which is not compatible with 2017 (Or you will have to play with dlls, and you don't want that).

The simpler is to compile pthread ourselves. Get the archive ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip

Extract the directory pthreads.2

On a cmd window

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
cd C:\pthread\directory
nmake clean VC
copy pthread.h sched.h C:\Users\<myuser>\dependencies\include
copy pthreadVC2.dll C:\Users\<myuser>\dependencies\bin
copy pthreadVC2.lib C:\Users\<myuser>\dependencies\lib

Create a pkg-config file.

dirent.h

This is the same for dirent. A implementation, header only can be found here. https://github.com/tronkko/dirent Just copy the dirent.h in C:/User/<myuser>/dependencies/include

Install Xapian

That's a tricky part. Xapian's team has started to make xapian support MSVC compilation. It should be available in the next release but for now we have to use the master branch of the git repository.

Le's go : .. In a cmd window :

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
# We want to keep the path to cl in msys shell
set MSYS2_PATH_TYPE=inherit
# We don't want to have msys messup our path of option `-Tp` (but it is ok for other options...)
set MSYS2_ARG_CONN_EXCL=-Tp
# Let's run our mingw64 shell
C:\msys2\mingw64.exe

A new window opens, let's use it:

#install things
pacman -S make autotools
git clone https://github.com/xapian/xapian
cd xapian
./bootstrap 
cd ..
export XAPIAN_SOURCE=$(pwd)/xapian/xapian-core
mkdir xapian-build
cd xapian-build
$XAPIAN_SOURCE/configure \
  CC="cl -nologo" \
  CXX="$XAPIAN_SOURCE/compile cl -nologo" \
  CXXFLAGS="-EHsc -MD" AR=lib \
  CPPFLAGS="-I/c/User/<myuser>/dependencies/include" \
  LDFLAGS="-L/c/User/<myuser>/dependencies/lib" \
  --disable-backend-remote \
  --prefix=/c/Users/<myuser>/dependencies

Mention the -MD options, because it is not added by default by xapian buildsystem. As meson will add it, we need it here else MSVC will complains at final link.

Do almost the same things on linux, but use ./configure --enable-maintainer-mode --disable-documentation
make xapian on linux.

On the msys2 window on Windows :

make

It will complain about missing (source) files, find them in xapian directory on linux and copy them on Windows. Then it will complain about missing man source (*.1), simply find then in the makefile and remove them (Makefile and doc/Makefile).

Finally

make
make install

You have succeed to compile xapian !

Install icu

dl archive http://download.icu-project.org/files/icu4c/62.1/icu4c-62_1-Win64-MSVC2017.zip
extract
create icu18n.pc

Build libzim

In cmd window:

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
git clone https://github.com/openzim/libzim
cd libzim
git checkout windows (when branch exists else patch)
meson . build --prefix C:/Users/<myuser>/dependencies --default-library static --buildtype release
cd build
ninja
ninja install

Build kiwix-lib

In cmd window:

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
git clone https://github.com/kiwix/kiwix-lib
cd kiwix-lib
git checkout windows (when branch exists else patch)
meson . build --prefix C:/Users/<myuser>/dependencies --default-library static --buildtype release
cd build
ninja
ninja install

Build kiwix-desktop

In cmd window:

C:\MSVC\VC\Auxiliary\Build\vcvars64.bat
git clone https://github.com/kiwix/kiwix-desktop
cd kiwix-desktop
git checkout windows (when branch exists else patch)
C:\Qt\5.1.10\msvc2017_64_bin\qmake.exe

qmake somehow generate an invalide makefile. Open Makefile.Release and fix it:

In the LIBS = ... line :

  • Change kiwix.lib, zim.lib and pugixml.lib to libkiwix.a, libzim.a and libpugixml.a
  • Add icuin.lib, icuuc.lib and icudt.lib after z.lib.

And, then :

make

In the release directory, there is a kiwix-desktop.exe !

Annexe

How to change path in windows

  • Right Click bottom left menu
  • Parameter
  • Information system
  • Associated Parameter
  • System information [new window]
  • Advanced system parameter [new window]
  • Env var

Find dll needed

You can use http://www.dependencywalker.com/