Introduction to Cygwin
Cygwin is a Linux-like environment for Windows. It consists of two parts:
- A DLL (cygwin1.dll), which acts as a Linux API emulation layer providing substantial Linux API functionality.
- A collection of nearly all GNU and related tools, ported so that they will run on a Windows host, but provide a Linux look-and-feel. These tools include shells, editors, file and bin utilities, and compilers, as well as services such as NFS and TFTP. They are provided as separate, installable packages.
Using Cygwin is nearly the same as working from a Linux host. Programs that are run on Cygwin do not use an emulator program, so they must be compiled for a Cygwin host machine – you can’t simply use a binary compiled for an x86 Linux host.
Cygwin is not a replacement for a Linux host. Cygwin is not a way to run native Linux applications on Windows, or to turn Windows applications into UNIX programs. Although you can use Cygwin to develop Linux target systems, it does not operate in the same manner as a Linux host. You are still using the Windows kernel and the underlying Windows processes. Therefore, the following limitations exist:
- Cygwin does not formally use the /proc or /dev filesystems, so you can’t create device nodes in the way that you would on a Linux system.
- There is no support for loopback devices.
- Because you still have the underlying Windows process and threading model, a fork would actually create a process, rather than do a true fork.
- Although you can compile a driver, insmod and programs that communicate directly with a Linux kernel won’t work.
Because of these limitations, you must rebuild your application if you want it to run on Windows, or if you want it to understand signals, ptys, and so forth.
Most of the development tools available from TimeSys are specifically designed to build and run on a POSIX-compliant system such as Linux. By providing a Linux-like environment on Windows, Cygwin allows TimeSys to build embedded systems development tools from the same source code we use to build Linux tools. These tools run on Windows using Cygwin, and provide the same interface that they do under Linux.
Like many open source projects, Cygwin is constantly and incrementally updated. In order to ensure that TimeSys customers have access to a known, tested, and stable Cygwin environment, TimeSys periodically takes a snapshot of the Cygwin project. We then make this snapshot available to our customers as a Cygwin distribution, consisting of the following:
- A known-good version of the Cygwin DLL
- A set of packages required by TimeSys development tools
- A custom installer used to simplify and streamline package installation
The LinuxLink Classic Repository allows you to easily download and install this version of Cygwin. Refer to Windows Host Considerations for system requirements.
Using Cygwin
After you have installed Cygwin, you can run C:\Cygwin\cygwin.bat (or double-click on a shortcut to this file) to open a Bash shell.
The Cygwin Filesystem on Windows
Cygwin installs a Linux-like filesystem in your Windows FAT32/NTFS filesystem. The root of the Cygwin (Linux-like) filesystem is C:\Cygwin (if you installed Cygwin in the default location), and from within Cygwin, you can access your C: drive by moving to /cygdrive/c. All of your other Windows drives also appear (are mounted under) /cygdrive.
Cygwin supports both binary and text mounting, which you can specify when you install Cygwin, shown in the following image. You can also specify the mounting type after installation. The mounting type determines how Cygwin treats end-of-line characters for text files. In general, you can use the default binary mode; Cygwin will almost always do end-of-line (EOL) and end-of-file (EOF) translation correctly. This option also makes execution under Cygwin faster. If you need to translate EOL characters for some DOS-style files, you can generally use the dos2unix utility.
Occasionally, you might need to use text mounting (turn translation on). For example, you might not be able to run the dos2unix utility on source-controlled files, or most of your files might have DOS-style EOL characters, and it would be cumbersome to run the utility for every file. Keep in mind that text mounting introduces additional overhead.
To change the mounting type after Cygwin is installed:
- Open a Cygwin Bash shell.
- Use the mount command to change modes. You might need to use the -f (force)
option, or Cygwin will inform you that the device or resource is busy.
- To change from binary to text mode, enter the following:
$ mount -t -f c:\\cygwin\\lib /usr/lib
- To change from text to binary mode, enter the following:
$ mount -b -f c:\\cygwin\\lib /usr/lib
- To change from binary to text mode, enter the following:
Cygwin allows case-sensitivity through the use of managed mounts, which tricks Windows into differentiating files of the same name with different cases. It is not foolproof. For more details regarding managed mounts, refer to the Cygwin FAQ at: http://cygwin.com/faq/faq.using.html.
Setting Up Your System
Refer to How to Configure Your Windows Host for the procedure that describes how to set up services for embedded Linux development. If you are installing a version of Cygwin that is not distributed by TimeSys, Cygwin Host Package Requirements lists the packages you must include in your installation.
Obtaining a Cygwin Cross Compiler
Cross compiling with Cygwin is fairly easy. Like anything else, getting the toolchain is the hard part. To get the toolchain, you can use one of the following methods, starting with the easiest one:
- Download the toolchain from LinuxLink – A TimeSys LinuxLink installs a toolchain in the standard /opt/timesys/toolchains/ location, and is ready to use for cross-compiling the indicated distribution.
- Build using the crosstool utility – Located at http://kegel.com/crosstool/, this utility maintained by Dan Kegel will download the appropriate source code, set up patches, and build the cross-compiler. This is approximately a 12 hour process.
- Build from scratch – Most of the scripts for GCC and related libraries will compile under Cygwin. You will have similar issues to those building under a Linux host.
Troubleshooting
The document Troubleshooting Problems with Cygwin Installed describes issues related to a Cygwin installation, and lists a few utilities that can be useful in troubleshooting.