Windows Subsystem for Linux (WSL)

In Windows 10, the Windows Subsystem for Linux (WSL) can be enabled in Windows Features. Supported Linux distributions, including Ubuntu, can then be installed from the Windows Store. This adds bash terminal to your Windows 10 platform, enabling you to compile and execute Linux CLI programs in it, and to execute bash scripts.

Microsoft provides installation and user guides for Bash on Windows.

Notice that Windows disks and directories are found under /mnt/. For example, Windows folder C:\Seafile can be accessed as /mnt/c/Seafile in Bash on Windows.

Your Bash home directory is located in C:\Users\username\AppData\local\lxss\home. Folder is hidden by default in Windows, but can be accessed by writing the path directly. If you edit files in Windows they may seem to disappear from the Bash; touch in Bash may reinstate the file, but safest option may be to copy file in Bash to a temporary location for editing and then copy the edited file back to its position, again in Bash.

You can check which version of Ubuntu is installed with command:

lsb_release -a

When a new LTS release of Ubuntu is available, it can be updated with command:

sudo do-release-upgrade

Ruby users may need to update that, too, and possibly reinstall some packages:

sudo apt-get install zlib1g-dev libssl-dev ruby-nokogiri
sudo gem update --system
sudo gem update
sudo gem install rubypants systemu kramdown nokogiri w3c_validators

Environment settings

In the Bash on Windows, go to your home directory, and list its contents:

cd
ls -al

In the home directory (usually /home/username) the hidden files .bashrc and .profile contain settings that may want to change. Currently, .profile is not loaded by default, thus edit the .bashrc file instead. For example, you can modify the PATH so that it includes the path to TPCCLIB linux binaries:

if [ -d "~/tpcclib/wsl/bin" ] ; then
    PATH="~/tpcclib/wsl/bin:$PATH"
fi

, and if Windows language is not English, you may also want set the language in bash to English:

export LANG=en_US.UTF8

, or in WSL shell with command:

sudo update-locale LANG=en_US.UTF8

You need to relaunch bash for these changes to take effect.

Compiling TPCCLIB in WSL

After installing the Bash on Windows, you will need to update it, and install the necessary toolchains:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install doxygen

After that you can follow the general instructions on compiling the TPCCLIB libraries and executables. Makefile system generator does not need to be defined with cmake in WSL, that is, option -G is not necessary.

Compiling for Linux

In order to compile binaries for Linux, install for WSL, test, and make Linux binary package, enter the following commands (changing paths as necessary), assuming that source codes are in path /home/me/tpcclib/src:

cd /home/me/tpcclib
mkdir wsl
cd wsl
cmake ../src
make -j 4 install
ctest --output-on-failure --parallel 4
cpack --config CPackConfig.cmake

Cross-compiling for Windows

It is possible to cross-compile Windows binaries in WSL. To do so, you must first install mingw-w64 in WSL. Notice that it will take some time and over 1 Gb disk space.

sudo apt-get install mingw-w64 
sudo apt-get install gcc-5-locales

CMake needs toolchain files, which are provided in the source package for 64-bit and 32-bit compilation. Example for building 64-bit binaries for Windows:

cd /home/me/tpcclib
mkdir mw64
cd mw64
cmake -DCMAKE_TOOLCHAIN_FILE=../src/toolchain-cross-mingw64-linux.cmake ../src
make -j 4 install
cpack --config CPackConfig.cmake

For building 32-bit binaries for Windows you just need to use different toolchain file:

cmake -DCMAKE_TOOLCHAIN_FILE=../src/toolchain-cross-mingw32-linux.cmake ../src


See also:



References:

Blum R, Bresnahan C. Linux Command Line and Shell Scripting Bible. 3rd ed., Wiley, 2015, ISBN: 978-1-118-98384-3.

Janssens J. Data Science at the Command Line. O’Reilly, 2014, ISBN 978-1-491-94785-2.

LinuxCommand.org

Pro Bash Programming (buy e-book from Apress)

van Vugt S: Beginning the Linux Command Line, 2nd edition. Apress, 2015. ISBN 978-1-4302-6829-1.

Wikibooks: Bash Shell Scripting


Tags: , , , , , , , ,


Created at: 2016-08-03
Updated at: 2018-09-10
Written by: Vesa Oikonen