Using UNIX Emulator Software on Windows

If you have a Windows laptop, there are UNIX emulators that make it possible to do the coding work for this class on your laptop. Similar capabilities are available on Apple machines as well, but since I don't have an Apple machine, I can only go into details on the Windows process.

A Unix emulator provides the capability of opening a terminal window on your laptop that looks and feels like a terminal window on a UNIX machine. You get a command line with a prompt where you can type commands. The response to those commands is typed back to the screen and another prompt appears. The default disk space in your UNIX emulator will be a sub-directory of your windows disk. That means that you can use either UNIX commands such as "ls" to list the contents of that directory, or you can use Windows Explorer to look at the same list of files. You can edit files using a windows editor such as Notepad, and those edits will be visible in your terminal window.

In a real UNIX terminal window, there are commands for tools such as editors or web browsers which open up full screen applications in separate windows. These commands will not work in a terminal emulator (without lots of extra effort which frankly is not worth it.) However, it is possible to run Windows commands from a UNIX emulator terminal window which run in full screen. For instance, there is a Windows version of gedit that you can install on Windows, and make available to the UNIX emulator so you can invoke gedit from the terminal emulator.

Contents:

Choosing a UNIX emulator

There are two good UNIX emulators that run in a Windows environment, Cygwin and git-bash. There may be other alternatives as well, such as Windows Subsystem, and there are always new software becoming available, but Cygwin and git-bash both have the advantage of being free to install, relatively easy to use and maintain, and which provide all the tools necessary to do work for this class.

The difference between Cygwin and git-bash is that Cygwin is bigger, more flexible, and more extendable, and more all-encompasing. git-bash is smaller, easier to install, but the native git-bash is not extendable, and so separate installations are required for extended capability. Because Cygwin is bigger and more flexible, you need to invest a little more time and effort up front to install and maintain Cygwin. If you are looking for a UNIX emulator you can use for the rest of your academic career, Cygwin might be the best answer. If you are looking for the quickest and easiest solution, go for git-bash. But to tell the truth, either Cygwin or git-bash work equally well, and installation efforts are not very different, so choose whichever you prefer.

Back to Contents

Installing git-bash

The git-bash tool contains a very basic UNIX emulator. The primary purpose of git-bash is to enable Windows users to use the "git" tool, which is used to keep track of multiple versions of software projects. We are not using the git tool to manage our software in this class, but along with git, when we install git-bash, we get a terminal emulator which is very useful.

Since git-bash is relatively small, installing git-bash is pretty simple.

  1. Open web page https://gitforwindows.org/, and click on the "Download" button.
  2. Run the git install code you have downloaded. This will start an installation dialog.
  3. The installation dialog will ask lots of questions. If you don't know what to answer, just choose the default answer. The only non-default answer I chose was to allow git to manage newlines for me. (Windows convention is that new lines consist of two unprintable characters -- carriage return (\CR) and line feed (\LF), but UNIX uses a single newline (\n) character. The git-bash utility will translate these for you if you choose to do so.)
  4. You may choose to make a short-cut to git-bash on your desktop after it has been installed.

Note that git-bash does not include a full-screen editor (it does include "vi" which is a command line editor, but "vi" is not easy to use.)

Note also that git-bash does not include the compiler (gcc), the debugger (gdb), and the make commands we will need for this class. These need to be installed separately. See #Installing MingW for details on how to get these tools and make them available in your git-bash terminal window.

Back to Contents

Running git-bash

Double click on the Git Bash icon to open a git-bash terminal window. git-bash will open a terminal window titled "MINGW64...", which stands for "Minimum Gnu for Windows 64 bit". Your "home" directory will be your standard Windows user directory, namely C:\Users\userid, where userid is your Windows user id.

You can use all the standard UNIX commands, such as ls, mkdir, cd, pwd, and cat. You can access your U drive (if you have it mounted) by using the specification "/u". You should also be able to use all the git commands such as git clone, git commit, git push, etc.

Once you have installed MingW on your laptop and updated your Path variable (see MingW Installation you can invoke the gcc editor, the gdb debugger, or the make command in exactly the same way you would in a UNIX environment.

One detail you need to be aware of. When you run the gcc compiler, it will produce a binary executable file as an output. For instance, if you run the command gcc -g -Wall -o hello helloWorld.c, in the UNIX world, gcc would produce an executable file called hello with no filetype. You could then type ./hello to run this command. When you run the gcc command in a UNIX emulator, the UNIX emulator knows it is running in a Windows environment, and writes an executable file called hello.exe. The gcc command adds the ".exe" file type to tell Windows this is an executable file. However, when you go to run the command ./hello, the UNIX emulator looks FIRST for an executable file called hello in the current directory. If it doesn't find one, it looks for a file called hello.exe, and runs that.

Normally you wouldn't care that under the covers that the UNIX emulator added the .exe filetype to your file. However, if using your U drive, and you have compiled on a real UNIX platform, then there will be a file called hello in your directory that will work on a real UNIX platform, but will not work in the UNIX emulator. Even though you compiled from within the UNIX emulator and created the file hello.exe, the emulator still tries to run hello first, and fails with an error message. Fix this problem by either deleting the hello file using the command rm hello, or by invoking hello using the command ./hello.exe to explicitly run the version of the executable file with the .exe filetype.

You can cut, copy, and paste from or to the git-bash terminal window, but the shortcut command Ctrl-C, Ctrl-X, and Ctrl-V will not work. The terminal emulator doesn't want UNIX cut copy and paste to get confused with Windows cut copy and paste. I always right mouse in the git-bash terminal window when I want to do a cut, copy, or paste instead of using shortcuts.

The git-bash terminal window is configurable. Go to the title bar that has a git-bash icon and says "MINGW64" on the left side, and right click on that icon to see the options you have. You can change the default size, fonts, background and foreground colors, etc. etc.

Back to Contents

Installing Cygwin

There are two major parts to Cygwin - a setup tool and the emulator itself. The setup tool is a full screen windows application that steps you through the process of configuring, downloading, and building the emulator itself. There are millions of configuration choices with Cygwin, so its nice to have a full-screen application to walk you through the process.

Note that if run the setup tools the first time to make the Cygwin emulation tool, and then realize you want to change some configuration choices, you can re-run the setup tool. The setup tool remembers your first choices and only downloads the new things it needs before rebuilding your Cygwin emulator.

  1. Start off the Cygwin installation process by downloading the Cygwin Setup tool from https://www.cygwin.com (You get to choose between the 64 bit version and the 32 bit version. If you don't know which you need, you probably want the 64 bit version. Most laptops are have 64 bit micro-processors these days.) Keep this executable file on your laptop. You will use it to do your initial installation of Cygwin, and also to update Cygwin to get new versions of the software you have chosen, or to reconfigure Cygwin.
  2. Once you have downloaded the setup program, run it. You will want to install from the internet, accept default root directory, install for all users, use the default local package directory, and use a direct internet connection. Once you have stepped through these screens, you will be asked to choose a download site. Any one should be fine. Then setup will download configuration options and put you in the "Select Package" screen. This is where you choose the set of optional software you want included with your Cygwin emulator.
  3. There are an enormous number of packages that you can choose to install or not to install with Cygwin. The more packages you install the longer it will take to download the packages and to build the Cygwin emulator, so the trick is to pick everything you need, but not pick the stuff you don't need. Most of these packages are dependent on other packages, but the Cygwin setup tool knows about all these dependencies, and if you select a package, Cygwin will automatically select all the other packages that are required as well. That means choosing just 3 or 4 packages may end up needing 20 or 30 packages to satisfy all the dependencies.

    On the "Select Package" screen, there is a "View" button with a pull-down list of options. I like to start with "Category" selected. If there is a "+" in the box next to "All", click on it, and you will get a list of categories. Then expand the "Devel" category. You will need to select the "gcc-core" package, the "gdb" package, and the "make" package, which all appear in the "Devel" category. You may want to install some other packages, or you may want to get a feel for things as they are, and if you need something later, you can always re-run the setup tool.

  4. Once you have selected the packages you want, hit the "Next" button. If you are re-running the setup tool, it will check to see if there are new versions of packages you already have installed, and select those packages for you as well.
  5. Next, confirm the list of packages (now you see all the dependencies expanded, and new versions selected). At this point, the setup program will uninstall previous versions of packages (if there), download the new versions of selected packages, and then rebuild the Cygwin emulator. Make sure you have a good network connection when you do this, because lots of stuff needs to be downloaded. The build process itself can also take quite a while, and the progress indicators on the screen aren't terribly helpful... but be patient.
  6. I sometimes get "Postinstall script errors", but ignoring these seems to be OK. Make your choice about icons, and click "Finish", and you are done. You have built a Cygwin terminal emulator.

Back to Contents

Running Cygwin

The Cygwin install process created (by default) a subdirectory on your Windows hard disk at "C:\cygwing64". You can look at this using Windows Explorer by going to "This PC", and then going to you C: disk, and then the "cygwin64" subdirectory.

Double click on the Cygwin64 Terminal icon (or Cygwin Terminal icon) to open a Cygwin terminal window. Your home directory will be on your windows drive "C:\cygwin64\home\userid", where userid is your Windows userid.

You can use all the standard UNIX commands, such as ls, mkdir, cd, pwd, and cat. Since you have chosen the gcc-core, gdb, and make packages, you will also be able to run the gcc command, the gdb command, and the make command. You can access your U drive (if you have it mounted) by using the specification "/cygdrive/U". You should also be able to use all the git commands such as git clone, git commit, git push, etc.

One detail you need to be aware of. When you run the gcc compiler, it will produce a binary executable file as an output. For instance, if you run the command gcc -g -Wall -o hello helloWorld.c, in the UNIX world, gcc would produce an executable file called hello with no filetype. You could then type ./hello to run this command. When you run the gcc command in a UNIX emulator, the UNIX emulator knows it is running in a Windows environment, and writes an executable file called hello.exe. The gcc command adds the ".exe" file type to tell Windows this is an executable file. However, when you go to run the command ./hello, the UNIX emulator looks FIRST for an executable file called hello in the current directory. If it doesn't find one, it looks for a file called hello.exe, and runs that.

Normally you wouldn't care that under the covers that the UNIX emulator added the .exe filetype to your file. However, if using your U drive, and you have compiled on a real UNIX platform, then there will be a file called hello in your directory that will work on a real UNIX platform, but will not work in the UNIX emulator. Even though you compiled from within the UNIX emulator and created the file hello.exe, the emulator still tries to run hello first, and fails with an error message. Fix this problem by either deleting the hello file using the command rm hello, or by invoking hello using the command ./hello.exe to explicitly run the version of the executable file with the .exe filetype.

You can cut, copy, and paste from or to the Cygwin terminal window, but the shortcut command Ctrl-C, Ctrl-X, and Ctrl-V will not work. The terminal emulator doesn't want UNIX cut copy and paste to get confused with Windows cut copy and paste. I always right mouse in the Cygwin terminal window when I want to do a cut, copy, or paste instead of using shortcuts.

The Cygwin terminal window is configurable. Go to the title bar that has a terminal icon and says "bash" on the left side, and right click on that icon to see the options you have. You can change the default size, fonts, background and foreground colors, etc. etc.

Back to Contents

Choosing an Editor

There are several different editors you can use in a Windows environment, all that can be invoked from a terminal emulator window if you have them set up correctly. Some of these are even packaged with Windows, so you don't need to install them. Your choices include the following (this is by no means a complete list, but these are the interesting ones I know of.):

vi
A command line editor (not full-screen) that is very powerful, and comes for free if you install git-bash, but you have to make a big investment to learn all the vi commands before you can really be proficient using vi. I don't recommend this one. It takes too long to learn how to use it well.
notepad
This is a full-screen Windows editor, but it is very basic, and does not support UNIX newlines, so is vitually unusable in our context.
wordpad
This is a full-screen Windows editor which can be invoked from a UNIX emulator terminal window using the command: wordpad filename&. Wordpad will handle UNIX newlines, but it does not do any syntax highlighting or curly brace matching, so even though this is easy and already available, I don't recommend it.
gedit
This is a free editor provided by the "gnome" organization, and it's a Windows version of the same editor we use in the lab. The installation instructions are at Installing gedit on Windows. Once you have installed gedit, and updated your windows Path variable, you can invoke gedit from a UNIX emulator terminal window using the command: gedit filename&. This is the easiest editor to install and use in this context.
Notepad++
Notepad++ is a free editor provided you can download and install on you Windows machine. It has sophisticated highlighting and is very flexible with lots of configuration options. Once you have installed Notepad++ on your Windows machine, and updated you Windows Path variable to point to Notepad++, you can invoke it from a UNIX emulator terminal window using the command: notepad++ filename&.
TextPad
TextPad is a Windows editor I've been using for a long time (before some of the others were available) because it handles UNIX newlines, does syntax highlighting, and has some other nice features such as "block" editing that were not available on other editors at the time. TextPad is free to install, but asks you to contribute each time you start it up until you buy a license.

I've installed and used all of these editors in my career, but would recommend gedit as the easiest, most intuitive, and sufficiently powerful and productive to do everything we need to do in this class.

Back to Contents

Installing gedit on Windows

The gedit editor is free software, one of the components of software built by the "gnome" organization (See https://www.gnome.org for more details.). Many of the UNIX based systems around campus use gnome software for a UNIX desktop and tool suite, so students are often familiar with the gedit editor.

Download the gedit install package by going to https://download.gnome.org/binaries/, and choosing the platform that matches your laptop, and then choosing the "gedit" folder. Download the ".msi" (Microsoft Install) file, and double click on it. This will take you through the gedit install process. This will not make a new desktop icon, but that's OK. We won't be invoking gedit from the desktop, but from our UNIX emulator terminal window via the command line.

In order to invoke from the command line, we need to tell Windows where to find our newly installed gedit command. In order to do this, we need to update the Windows "PATH" variable. Do this by:

  1. Opening Windows Explorer, and finding the "This PC" icon in the list on the left side of the screen.
  2. Left click on "This PC", and choose "Properties".
  3. On the resulting screen, left click on "Advanced System Settings".
  4. On the resulting System Properties window, at the bottom of the "Advanced" tab is an "Environment Variables..." button. Left click on that button.
  5. This brings up an "Environment Variables" screen. On the bottom half, under "System Variables", scroll until you find the "Path" variable. Click on that line to select it, and choose "Edit...".
  6. This brings up the "Edit environment variable" window. Click on the "Browse..." button.
  7. In the Browse window, expand "This PC", then C:, then "Program Files", then "gedit", then select "bin", and click on the "OK" button.
  8. This will put "C:\Program Files\gedit\bin" at the bottom of the list on the "Edit Environment variable" window. Click "OK" to get back to the "Environment Variables" window.
  9. Click "OK" on that window to get back to "System Properties".
  10. Click "OK" on that window to get back ot the "System" window.
  11. Close that window.

Now you should be able to run "gedit filename" from the UNIX emulator terminal window.

One note... The first time you invoke gedit from a terminal window, make sure you add an ampersand (&) to the end of the command so that gedit can "run in the background"... in other words you can run the editor and the command line window at the same time.

Once gedit is up and running, the next time you invoke gedit for a different file, it does not start a new gedit window... it just sends your new file to the existing gedit window which is already running in the background. The existing gedit window will open a new tab for the new file. For this reason, you don't need to run the second invocation in the background (although runnning it in the background won't hurt anything.

When you close your editor, the next time the terminal window updates, you will see a message such as [1]+ Done gedit hello.c to indicate that the background job has finished.

Back to Contents

Installing MingW

MingW stands for "Minimal GNU for Windows". This is a package that contains several GNU tools ported into a Windows environment, including the GNU C compiler (gcc), the GNU debugger (gdb), and the GNU make command (make), all of which we need for this course. MingW can get complicated, but we need only the simplest installation. The following instructions descrdibe how to download and install the basic MingW pacakge we will be using.

  1. Open a Web Browser to http://www.mingw.org/. Click on the "Downloads" hyperlink.
  2. Find the download button for "mingw-get-setup.exe", and download it.
  3. When the download is finished, run the binary executable "mingw-get-setup.exe". This will start the installation dialog.
  4. Accept all the default options, and continue through the dialogue. This will install and start the MingGW installation manager.
  5. In the installation manager, click on the row named "mingw32-base-bin", and choose "Mark for Installation".
  6. Then, on the Menu, choose "Installation/Apply Changes". This will bring up a confirmation menu that shows what you will install. Continue, and the packages you need will be downloaded and installed.
  7. Close the MingW installer.
  8. Add C:\Program Files(X86)/mingw64/i868-8.1.0-posix-drawf-rt_v6-rev0/mingw32/bin to your Path

Now that you have installed MingW, you need to add MingW to your path so that git-bash can find the tools in MingW. Add to your path by doing the following steps...

  1. Open Windows Explorer, and finding the "This PC" icon in the list on the left side of the screen.
  2. Left click on "This PC", and choose "Properties".
  3. On the resulting screen, left click on "Advanced System Settings".
  4. On the resulting System Properties window, at the bottom of the "Advanced" tab is an "Environment Variables..." button. Left click on that button.
  5. This brings up an "Environment Variables" screen. On the bottom half, under "System Variables", scroll until you find the "Path" variable. Click on that line to select it, and choose "Edit...".
  6. This brings up the "Edit environment variable" window. Click on the "Browse..." button.
  7. In the Browse window, expand "This PC", then C:, then "MinGW", then select "bin", and click on the "OK" button.
  8. This will put "C:\MinGW\bin" at the bottom of the list on the "Edit Environment variable" window. Click "OK" to get back to the "Environment Variables" window.
  9. Click "OK" on that window to get back to "System Properties".
  10. Click "OK" on that window to get back ot the "System" window.
  11. Close that window.

Back to Contents