Windows Subsystem for Linux (WSL)

In Windows 10 and 11, the Windows Subsystem for Linux (WSL) can be installed from Microsoft Store. WSL requires that virtualization is enabled in BIOS settings, and that virtual machine environment is enabled in the Windows Features. Supported Linux distributions, including Ubuntu, can then be installed from the Windows Store. This adds bash terminal to your Windows 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. Alternatively, you can follow the specific installation guides for Ubuntu on WSL.

Notice that Windows disks and directories are found in Ubuntu under /mnt/. For example, Windows folder C:\Seafile can be accessed as /mnt/c/Seafile in Ubuntu. Processes like compilation that are highly dependent on time stamps should not be performed in Windows disks to prevent "modification time is in future" errors. Use your Linux home directory instead.

You can open a Windows File Explorer window directly in the current directory from within a Linux shell environment by typing the following command into the Bash shell:

explorer.exe .

You can work with files normally from here, even open them directly in Windows applications to modify them. File explorer shows the Windows folder where your Bash home directory is located in Windows, for example folder \\wsl$\Ubuntu-20.04\home\username. While editing files via File explorer is safe, other means for accessing the files from Windows may not work well and edited files may seem to disappear from the Bash; touch in Bash may reinstate the file, but safest option may be to copy file to a temporary location for editing and then copy the edited file back to its position.

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

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 need to be changed, but preferred method is to leave these files as they are, and instead create a file .bash_aliases with the required settings. For example, with the following contents of .bash_aliases you can modify the PATH so that it includes the path to the TPCCLIB Linux binaries (in your system the folder is probably different):

PATH="~/git/tpcclib/build/bin:$PATH"

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.

Configuration files can be viewed in Windows Explorer.

Compiling TPCCLIB in WSL

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

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt install build-essential
sudo apt install cmake
sudo apt 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 ~/git/tpcclib/src:

cd ~/git/tpcclib/
mkdir build
cd build
cmake ../src
make -j 4 install
ctest --output-on-failure --parallel 4
make package

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 install mingw-w64 
sudo apt install gcc-5-locales

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

cd ~/git/tpcclib
mkdir mw64
cd mw64
cmake -DCMAKE_TOOLCHAIN_FILE=../src/toolchain-cross-mingw64-linux.cmake ../src
make -j 4 install
make package


See also:



Literature

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: , , , , , , , ,


Updated at: 2023-02-05
Created at: 2016-08-03
Written by: Vesa Oikonen