## Run Linux Apps with Frontend in Windows through CygwinX

Say you work somewhere where all workstations run Linux, only you have Windows on your laptop, which you basically use all the time. Now as I type this, I am not sure if anyone else shares my fate. Anyway; this does not stop you from running some of the cool Linux tools. Just install CygwinX (through the regular Cygwin installer) and start the XServer from the start menu. Icons will appear in your taskbar and you can start an XTerm. Inside that XTerm, type:
rattle@windows.box$ssh -Y rattle@linux.box Password: Last login: Thu Sep 17 12:43:19 2015 from windows.box rattle@linux.box$ xmaple

and there you go! The -Y switch is the one that does all the magic, obviously.

## Make VIM work in Cygwin

Well. In case you have not stumbled across the corresponding StackOverflow post, and if you have always wondered why vim does not work properly in cygwin, just
[rattle@ALICE:~]$cat .vimrc set nocompatible set backspace=indent,eol,start  and your worries will be over. ## Keep Cygwin Applications from setting NTFS security descriptors If you run cygwin applications such as [the rsync-backup script](/2014/01/31/incremental-backups-with-rsync-in-windows/), you will sometimes run into trouble with odd NTFS permissions being set by the cygwin application. My tip is to avoid this by making cygwin not set *any* permissions at all. If a cygwin application then creates a file, for instance, this file will only inherit its security settings from the folder it is contained in. This way, you can set access control on the root directory and all the files created by rsync inside that folder will inherit these permissions. How to do it? Open your cygwin shell and edit /etc/fstab which should contain only one non-comment line: none /cygdrive cygdrive binary,posix=0,user 0 0  Now insert the noacl attribute, see [the cygwin manual](http://www.cygwin.com/cygwin-ug-net/using.html#mount-table): none /cygdrive cygdrive binary,noacl,posix=0,user 0 0  And the next time you run rsync-backup, it will *not* set all kinds of awkward permissions on your files which make them unreadable on a freshly installed computer. Just saying. ## Import & Export Cygwin List of installed Packages If you want to go from 32 to 64 bit [Cygwin](http://www.cygwin.com) but keep all the packages1, you might find yourself in a spot where you would like to export the list of cygwin packages and also be able to install cygwin with all these packages again. I will tell you how. Open your Cygwin shell and enter grep " 1$" /etc/setup/installed.db | awk '{print $1}' > packagelist  This will dump a list of all *selected* packages and is the kind contribution of Yamakuzure-san. Earlier, I had proposed the following command: cygcheck -c -d | sed -e "1,2d" -e 's/ .*$//' > packagelist

which will simply dump a list of *installed* packages, including all the dependencies (possibly cluttering up your cygwin backup file). In the comments below you'll see that my command worked better in one case. If you decide to try both, leave a comment about how they performed for you. To install Cygwin 64 from such a package file, download [setup-x86_64](http://cygwin.com/setup-x86_64.exe). Of course, this will also work with the old [setup-x86.exe](http://cygwin.com/setup-x86.exe) if you are reading this just for the sake backing up your cygwin install configuration. Execute the installer with the command line parameters
./setup-x86_64 -P awk 'NR==1{printf $1}{printf ",%s",$1}' packagelist

The **awk** command reads your file and turns it into a comma-separated list, then this string is passed as the argument to the **-P** option of the installer. It may not be documented with great detail in the [Cygwin installer command-line options](http://cygwin.com/faq/faq.html#faq.setup.cli), but CSV is exactly what the **-P** option expects. Since you might want to use **cygcheck** to backup your cygwin-install, you might not have **awk** and a bash shell at your disposal at the time of install. However, you should certainly have some kind of python installed already. Here is a python script that will read your packages correctly and install cygwin with them selected:
from urllib import request
import sys, getopt, subprocess
build = 'x86'
packagefile = 'packagelist'
opts, args = getopt.getopt(sys.argv[1:],'',['64','packages='])
for o,a in opts:
if o == '--64': build = 'x86_64'
if o == '--packages':
packagefile = a
setupfile = "setup-%s.exe" % build
packages = ','.join([ x.strip() for x in open(packagefile).readlines()])
r = request.urlopen("http://cygwin.com/%s" % setupfile)
subprocess.call([setupfile, '-P', packages ])

In fact, it first downloads the current setup executable from the cygwin server and then launches it. It accepts the option --64 to install 64 bit cygwin and the option --packages=packagelist to select a file with a list of packages.
1. At least those that are available. []

## GMP from source with MinGW-64

Under Cygwin, you can install the 64 bit mingw version of GCC, but you don't get the gnu multiprecision library for free with it, you'll much rather have to compile it from source. I ran into a bit of trouble here: It will not suffice to tell the configuration script about the new compiler, there are now mingw-64 versions of all relevant binaries that should be used instead. Basically, you go like
tar -xjf gmp-5.0.4.tar.bz2
cd gmp-5.0.4
./configure                          \
AR=x86_64-w64-mingw32-ar           \
AS=x86_64-w64-mingw32-as           \
DLLTOOL=x86_64-w64-mingw32-dlltool \
DLLWRAP=x86_64-w64-mingw32-dllwrap \
CC=x86_64-w64-mingw32-gcc-4.5.3    \
NM=x86_64-w64-mingw32-nm           \
LD=x86_64-w64-mingw32-ld           \
OBJDUMP=x86_64-w64-mingw32-objdump \
RANLIB=x86_64-w64-mingw32-ranlib   \
STRIP=x86_64-w64-mingw32-strip

I am not sure if all of these are needed, but it won't hurt either. After that, you should
make && make check

the whole thing. Worked perfectly for me, so now I can link with libgmp.a in .libs and native 64 bit bignum action ensues!