Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Cygwin: UNIX/Linux Shell Environment and Portability Layer


April 2000

Cygwin: UNIX/Linux Shell Environment and Portability Layer

Marcel Gagné

While the rapidly increasing popularity of Linux has Windows users asking "But will I be able to run my Windows software in Linux?", we sometimes forget that there is another side to that question. Seasoned UNIX and Linux users know that working on a Windows platform (as they sometimes must in the workplace) means giving up the power afforded by the tools they must leave behind every time they boot Windows.

The GNU Public License and the Open Source movement has given us a plethora of tools beyond even the basics of the trusty command line. These powerful tools not only do the job, they do the job at a cost that is considerably less than their proprietary counterparts. Abandoning them is something most UNIX users would rather not think about.

Enter Cygwin, formerly from Cygnus solutions, now from Red Hat Software. Cygnus, as some of you may know, was recently acquired by Red Hat Software. Cygwin is a collection of GNU tools ported to Windows (95, 98, NT) using the Cygwin runtime library. Furthermore, Cygwin allows a developer to use the standard Win32 API or Cygwin's runtime (which actually makes more sense -- more on that later). Cygwin comes with the GNUPro gcc compiler, debugging tools, and more. Best of all, Cygwin brings a little of what makes UNIX and Linux so great to your Windows system.

Installation

This is pretty much a standard Windows installation. If you are installing from the CD (as I was), it should run the setup.exe file when your autorun file is detected by Windows. If it does not start automatically, simply change directory to your CD drive and execute the file manually. For example, on my notebook, the CD was drive letter E:.

E: SETUP.EXE

You'll be asked to consider shutting down all Windows programs while the installation takes place (you know the drill). After you agree to the terms of the GNU Public License (under which Cygwin is distributed) and get a little information about Cygnus software, you will choose your installation directory. The install defaults to C:\Cygwin but it can easily be changed. In my case, I used D:\Cygwin since space was at a premium on my C: drive. This brings us to the space requirements.

A full install of Cygwin (including source code) takes roughly 1.2 GB of disk space. You can trim that a fair bit simply by not installing the source code. On its own, the source takes up about 835 KB of disk. In reality, you only need the source if you want to tweak Cygwin or recompile it yourself.

Click "Next" and the install will proceed. Cygwin will make some changes to your AUTOEXEC.BAT file and add its /bin directories to the default executable PATH. When the install is done, reboot Windows.

Documentation

Cygwin comes with full online documentation as well as a bound manual. The manual is clean and easy to read; however, the presentation of ideas is a little odd and sometimes downright confusing. There were instances when I found myself wondering how "this" followed "that". The manual is pretty much just a "getting started guide". It is a good guide to get you hooked, but you'll definitely be checking out the online documentation and Cygwin's Web site for more. Still, half the fun of Cygwin comes from working with it, not reading about it. It is my opinion that UNIX and Linux systems people will quickly put aside the manual and jump right in.

Working with Cygwin
When I saw that bash dollar sign prompt, I was so thrilled at the possibilities of working in an environment that (as a UNIX enthusiast) I actually consider easier than Windows, that I spent the next hour trying out commands. Using the -V flag on Perl shows it to be version 5.003. Yes, you can use the --color option on ls. Good. The fortune program recognizes the normal flags. Good. gnuchess seems to work just fine. Enough fun and games. What about real work?

A df showed me only my "root" partition (actually D:\Cygwin, my install directory. I found that interesting but decided to try to mount my C: drive.

$ mkdir /mnt/cdrive
$ mount c:\ /mnt/cdrive
$ df

Pretty easy and straightforward for the seasoned Linux or UNIX user.

Compiling programs are where you'll find Cygwin a bit more interesting. Since not everything is in what you might think of as "standard" locations, some modifications to default Makefiles may be necessary. That said, program sources that use a "configure" script didn't give me a lot of grief. I decided to give Cygwin a fairly tough test, a network application, since I thought it would bring a number of elements into play. For my test, I picked up a sharp little text-only browser similar to lynx called w3m. Figure 1 As an aside to the test, I like w3m, because it renders tables and frames in a curses, or character-based environment.

Anyway, I downloaded the source code, and installed it with the following steps.


$ tar -xzvf w3m-0.1.6.tar.gz
$ cd w3m
$ ./configure
$ make
$ make install

In all cases during the configuration process, I simply took the defaults to see how Cygwin would behave itself. The one strange thing was its default choice of installation directory. This was /cygnus/cygwin-b20/H-i586-cygwin32/bin instead of something more "normal" like /usr/local/bin.

I found this a bit strange and pointed it out to my contact at Red Hat who said, "It's not supposed to do that." Apparently I had just run into a bug. You may find this to be an old problem by the time you read this article. In any case, it wasn't a big deal since I could override the default installation directories. In the case of single binary installations, moving or creating a symbolic link to the file would work just as well.

For C++ application developers, Cygwin comes with "Insight," a visual debugger. Finding Insight (no pun intended) was tougher than it sounds. I expected to be able to just type "insight" and suddenly it would appear. As it turns out, Insight is called with the command gdb (think "graphical debugger").

Cygwin Helps Save the Day
While I was busy writing this review, I received a panic call from a friend and colleague who had just suffered a blow in the form of the dreaded "Pretty Park" worm. This worm is like the Happy99 worm or the evil Melissa in that it reads the Outlook address book and mails itself to another group of unfortunates. It also has other nasty side effects, which I won't go into at this time, but suffice it to say that removing "Pretty Park" must be done in exactly the right order or terrible things will happen. My colleague was running a popular virus checker on his system which offered to remove the offending file (FILES32.VXD). That's where the trouble started. In the Windows registry, the worm adds an entry that forces all programs executed under Windows to reference FILES32.VXD. That file was now gone, which meant there was no way to zip up the files (which were too big to allow DOS copies to diskette) to do backups (which hadn't been done in a couple of weeks) and no way to launch any Windows application that might have helped in the process. Since regedit gets called in the same way, there was no way to fix the system either. A reinstall was called for but backing up the data was paramount.

Then, out of the blue, Sally, my wife and business partner, asked whether "that product" I was reviewing might in some way help. I hastily loaded Cygwin (the CD was in my notebook case), rebooted the beleaguered PC, and brought up bash. From the shell prompt, I was able to run things that normally required the Windows interface. Better yet, I had access to archival and compression utilities like tar and bzip2. With trusty GNU tools, we managed to break 26 MB of data down to four 1-MB tar.bz2 files and copy them to diskette. Rather than trust those few diskettes alone to the important financial data that desperately needed preserving, I opened an ftp session to my remote office and transferred the files across the Internet. Then, just to make sure, I telnetted from the bash shell (makes a nice ansi emulator and beats Windows telnet program) to my machine, extracted the archive, verified the health of the documents, and logged off.

With the comfort that my colleague's data was safe, I went about cleaning up the Windows system, and copied the Win95 CD-ROM to the disk (we had no DOS CD driver). Then, secure in the knowledge that my data was safe, I blew away Windows, rebooted in DOS, and started a clean installation. As I was working away in the bash shell, doing a little Linux/UNIX magic, my friend remarked that I seemed more comfortable working in this arcane environment than in Windows. Ain't it the truth!

A Note about Cygwin.dll

Part of what makes Cygwin such a valuable product for developers is the quick ports that are possible from UNIX directly to Windows. Much of this is the result of Cygwin's runtime libraries. Note that Cygwin is covered by the GNU Public License (GPL), which means that programs built with Cygwin.dll or libcygwin.a are subject to that same license and must also be distributed GPL. Check the "Resources" section for a link that will provide the full text of the GPL.

For companies that wish to develop proprietary software for use under Windows and do not wish to use this license, a "proprietary use license" is available. Interested parties should contact Red Hat for details and costs.

Like the Book says, "Windows NT != Windows 95/98"

Running Cygwin on 95 or NT looks pretty much the same on the surface, and a user sitting at a 95 workstation will notice little or no difference from an NT session. Still, there are some important differences and, essentially, it comes down to security. On NT, you have the capability of assigning user-based permissions, creating a /etc/passwd and /etc/group file to manage ACLs. This is done by mapping Win32 permissions to a more or less standard UNIX model. You can even run an inetd process and telnet into the NT server, thus providing access to a remote bash shell.

What about X?

Cygwin does provide some X support. The X-libs, while not distributed with the CD-ROM, are available from the Web site. I'm told that at this moment, this is still considered beta quality at best. Some things have already been ported that use X, including xemacs (which comes with the CD version) and an xfree86 server currently under development.

Conclusion

For UNIX or Open Source developers who want to maintain their investment in software by porting to Windows platforms, Cygwin is almost too good a deal to pass up. For those of us who are day-to-day UNIX administrators or users forced to work on Windows workstations, Cygwin is almost too good a deal to pass up. At $99 (U.S.) for the boxed set (which includes the manual, CD, extra contributed software, support, etc), this is a bargain. If you are happy working it out on your own and collecting the various bits of contributed software as you need the pieces, Cygwin will cost you even less. It is a free download from the Cygwin Web site.

One word on the free download vs. the boxed set. The CD-ROM comes with the Cygwin environment, full source code, and a great deal of contributed software including Perl, lesstif, xemacs, and more. It's not all work, though. In the contrib directory, you'll find the classic fortune program and gnuchess as well. It's a question of simplicity. You can also find a lot of this software if you simply visit the Web site and start digging. As with many Open Source projects, you'll find a community of people working with and developing with Cygwin.

Contact Information

Red Hat Software
http://www.redhat.com
P.O. Box 13588
RTP, NC 27709
In the U.S., call (800) 454-5502
Outside the U.S., call (919) 547-0012

Resources

Cygwin Web site: http://sourceware.cygnus.com/cygwin/
GNU Public License: http://www.gnu.org/copyleft/gpl.html
w3m Browser: http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/e

Marcel Gagné lives and works in the mythical city of Mississauga, Ontario. There, he is president of Salmar Consulting Inc., a systems integration and network consulting firm. He also writes science fiction and fantasy, and edits TransVersions, a science fiction, fantasy, and horror magazine. He has loved UNIX and all its flavours for more than 15 years now, and will even admit it in public. He can be reached at [email protected]. You can find out more from his Web site at www.salmar.com.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.