Cygwin

Get that Linux feeling - on Windows

Cygwin FAQ

Cygwin FAQ


1. About Cygwin
1.1. What is it?
1.2. What versions of Windows are supported?
1.3. Where can I get it?
1.4. Is it free software?
1.5. What version of Cygwin is this, anyway?
1.6. Who's behind the project?
2. Setting up Cygwin
2.1. What is the recommended installation procedure?
2.2. What about an automated Cygwin installation?
2.3. Does Setup accept command-line arguments?
2.4. Can I install Cygwin without administrator rights?
2.5. Why not install in C:\?
2.6. Can I use Cygwin Setup to get old versions of packages (like gcc-2.95)?
2.7. After upgrading from Cygwin 1.5 to Cygwin 1.7 my user mount points disappeared! How can I get them back?
2.8. Is Cygwin Setup, or one of the packages, infected with a virus?
2.9. My computer hangs when I run Cygwin Setup!
2.10. What packages should I download? Where are 'make', 'gcc', 'vi', etc?
2.11. How do I just get everything?
2.12. How much disk space does Cygwin require?
2.13. How do I know which version I upgraded from?
2.14. What if setup fails?
2.15. My Windows logon name has a space in it, will this cause problems?
2.16. My HOME environment variable is not what I want.
2.17. How do I uninstall individual packages?
2.18. How do I uninstall a Cygwin service?
2.19. How do I uninstall all of Cygwin?
2.20. How do I install snapshots?
2.21. Can Cygwin Setup maintain a ``mirror''?
2.22. How can I make my own portable Cygwin on CD?
2.23. How do I save, restore, delete, or modify the Cygwin information stored in the registry?
3. Further Resources
3.1. Where's the documentation?
3.2. What Cygwin mailing lists can I join?
3.3. What if I have a problem? (Or: Why won't you/the mailing list answer my questions?)
4. Using Cygwin
4.1. Why can't my application locate cygncurses-8.dll? or cygintl-3.dll? or cygreadline6.dll? or ...?
4.2. Why is Cygwin suddenly so slow?
4.3. Why can't my services access network shares?
4.4. How should I set my PATH?
4.5. Bash (or another shell) says "command not found", but it's right there!
4.6. How do I convert between Windows and UNIX paths?
4.7. Why doesn't bash read my .bashrc file on startup?
4.8. How can I get bash filename completion to be case insensitive?
4.9. Can I use paths/filenames containing spaces in them?
4.10. Why can't I cd into a shortcut to a directory?
4.11. I'm having basic problems with find. Why?
4.12. Why doesn't su work?
4.13. Why doesn't man -k, apropos or whatis work?
4.14. Why doesn't chmod work?
4.15. Why doesn't my shell script work?
4.16. How do I print under Cygwin?
4.17. Why don't international (Unicode) characters work?
4.18. My application prints international characters but I only see gray boxes
4.19. Is it OK to have multiple copies of the DLL?
4.20. I read the above but I want to bundle Cygwin with a product, and ship it to customer sites. How can I do this without conflicting with any Cygwin installed by the user?
4.21. Can I bundle Cygwin with my product for free?
4.22. But doesn't that mean that if some application installs an older Cygwin DLL on top of a newer DLL, my application will break?
4.23. Why isn't package XYZ available in Cygwin?
4.24. Why is the Cygwin package of XYZ so out of date?
4.25. How can I access other drives?
4.26. How can I copy and paste into Cygwin console windows?
4.27. What firewall should I use with Cygwin?
4.28. How can I share files between Unix and Windows?
4.29. Is Cygwin case-sensitive??
4.30. What about DOS special filenames?
4.31. When it hangs, how do I get it back?
4.32. Why the weird directory structure?
4.33. How do anti-virus programs like Cygwin?
4.34. Is there a Cygwin port of GNU Emacs?
4.35. Is there a Cygwin port of XEmacs?
4.36. What about NT Emacs?
4.37. Why don't some of my old symlinks work anymore?
4.38. Why don't symlinks work on Samba-mounted filesystems?
4.39. How do I setup sshd in a domain?
4.40. Why do my Tk programs not work anymore?
4.41. Why do I get "Address family not supported" errors when playing with IPv6?
4.42. What applications have been found to interfere with Cygwin?
4.43. How do I fix fork() failures?
5. Cygwin API Questions
5.1. How does everything work?
5.2. Are development snapshots for the Cygwin library available?
5.3. How is the DOS/Unix CR/LF thing handled?
5.4. Is the Cygwin library multi-thread-safe?
5.5. How is fork() implemented?
5.6. How does wildcarding (globbing) work?
5.7. How do symbolic links work?
5.8. Why do some files, which are not executables have the 'x' type.
5.9. How secure is Cygwin in a multi-user environment?
5.10. How do the net-related functions work?
5.11. I don't want Unix sockets, how do I use normal Win32 winsock?
5.12. What version numbers are associated with Cygwin?
5.13. Why isn't timezone set correctly?
5.14. Is there a mouse interface?
6. Programming Questions
6.1. How do I contribute a package?
6.2. How do I contribute to Cygwin?
6.3. Why are compiled executables so huge?!?
6.4. What do I have to look out for when porting applications to 64 bit Cygwin?
6.5. My project doesn't build at all on 64 bit Cygwin. What's up?
6.6. Why is __CYGWIN64__ not defined for 64 bit?
6.7. Where is glibc?
6.8. Where is Objective C?
6.9. Why does my make fail on Cygwin with an execvp error?
6.10. How can I use IPC, or why do I get a Bad system call error?
6.11. Why the undefined reference to WinMain@16?
6.12. How do I use Win32 API calls?
6.13. How do I compile a Win32 executable that doesn't use Cygwin?
6.14. Can I build a Cygwin program that does not require cygwin1.dll at runtime?
6.15. Can I link with both MSVCRT*.DLL and cygwin1.dll?
6.16. How do I make the console window go away?
6.17. Why does make complain about a "missing separator"?
6.18. Why can't we redistribute Microsoft's Win32 headers?
6.19. How do I use cygwin1.dll with Visual Studio or MinGW?
6.20. How do I link against a .lib file?
6.21. How do I build Cygwin on my own?
6.22. I may have found a bug in Cygwin, how can I debug it (the symbols in gdb look funny)?
6.23. How can I compile Cygwin for an unsupported platform (PowerPC, Alpha, ARM, Itanium)?
6.24. How can I adjust the heap/stack size of an application?
6.25. How can I find out which DLLs are needed by an executable?
6.26. How do I build a DLL?
6.27. How can I set a breakpoint at MainCRTStartup?
6.28. How can I build a relocatable dll?
6.29. How can I debug what's going on?
6.30. Can I use a system trace mechanism instead?
6.31. Why doesn't gdb handle signals?
6.32. The linker complains that it can't find something.
6.33. Why do I get an error using struct stat64?
6.34. Can you make DLLs that are linked against libc ?
6.35. Where is malloc.h?
6.36. Can I use my own malloc?
6.37. Can I mix objects compiled with msvc++ and gcc?
6.38. Can I use the gdb debugger to debug programs built by VC++?
6.39. Shell scripts aren't running properly from my makefiles?
6.40. What preprocessor macros do I need to know about?
6.41. How should I port my Unix GUI to Windows?
7. Copyright
7.1. What are the copyrights?

1. About Cygwin

1.1. What is it?
1.2. What versions of Windows are supported?
1.3. Where can I get it?
1.4. Is it free software?
1.5. What version of Cygwin is this, anyway?
1.6. Who's behind the project?

1.1.

What is it?

The Cygwin tools are ports of the popular GNU development tools for Microsoft Windows. They run thanks to the Cygwin library which provides the POSIX system calls and environment these programs expect.

With these tools installed, it is possible to write Windows console or GUI applications that make use of significant parts of the POSIX API. As a result, it is possible to easily port many Unix programs without the need for extensive changes to the source code. This includes configuring and building most of the available GNU software (including the packages included with the Cygwin development tools themselves) as well as lots of BSD tools and packages (including OpenSSH). Even if the development tools are of little to no use to you, you may have interest in the many standard POSIX utilities provided with the package. They can be used from one of the provided Unix shells like bash, tcsh or zsh, as well as from the standard Windows command shell if you have to for some sad reason.

1.2.

What versions of Windows are supported?

Cygwin can be expected to run on all modern versions of Windows. This includes, as of the time of writing this, Windows XP SP3, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, Windows Server 2012, Windows 8. The 32 bit version also runs in the WOW64 32 bit environment on released 64 bit versions of Windows (XP/2003/Vista/2008/7/2008 R2/8/2012). Since Cygwin is a community-supported free software project, patches to provide support for other versions would be thoughtfully considered. Paid support contracts or enhancements are available through Red Hat. For information about getting a Red Hat support contract, see http://cygwin.com/licensing.html.

Keep in mind that Cygwin can only do as much as the underlying OS supports. Because of this, Cygwin will behave differently, and exhibit different limitations, on the various versions of Windows.

1.3.

Where can I get it?

The home page for the Cygwin project is http://cygwin.com/. There you should find everything you need for Cygwin, including links for download and setup, a current list of mirror sites, a User's Guide, an API Reference, mailing lists and archives, and additional ported software.

You can find documentation for the individual GNU tools typically as man pages or info pages as part of the Cygwin net distribution. Additionally you can get the latest docs at http://www.gnu.org/manual/. (You should read GNU manuals from a local mirror. Check http://www.gnu.org/server/list-mirrors.html for a list of them.)

1.4.

Is it free software?

Yes. Parts are GNU software (gcc, gas, ld, etc...), parts are covered by the standard X11 license, some of it is public domain, some of it was written by Red Hat (or the former Cygnus Solutions) and placed under the GPL. None of it is shareware. You don't have to pay anyone to use it but you should be sure to read the copyright section of the FAQ for more information on how the GNU General Public License may affect your use of these tools.

In particular, if you intend to port a proprietary (non-GPL'd) application using Cygwin, you will need the proprietary-use license for the Cygwin library. This is available for purchase from Red Hat; please visit http://cygwin.com/licensing.html for more information. All other questions should be sent to the public project mailing list cygwin@cygwin.com.

Note that when we say "free" we mean freedom, not price. The goal of such freedom is that the people who use a given piece of software should be able to change it to fit their needs, learn from it, share it with their friends, etc. The Cygwin license allows you those freedoms, so it is free software.

1.5.

What version of Cygwin is this, anyway?

To find the version of the Cygwin DLL installed, you can use uname as on Linux or cygcheck. Refer to each command's --help output and the Cygwin User's Guide for more information.

If you are looking for the version number for the whole Cygwin release, there is none. Each package in the Cygwin release has its own version. The packages in Cygwin are continually improving, thanks to the efforts of net volunteers who maintain the Cygwin binary ports. Each package has its own version numbers and its own release process.

So, how do you get the most up-to-date version of Cygwin? Easy. Just download the Cygwin Setup program by following the instructions here. The setup program will handle the task of updating the packages on your system to the latest version. For more information about using Cygwin's setup.exe, see Setting Up Cygwin in the Cygwin User's Guide.

1.6.

Who's behind the project?

(Please note that if you have cygwin-specific questions, all of these people will appreciate it if you use the cygwin mailing lists rather than sending personal email.)

Christopher Faylor (cgf) is one of the project leads. Chris works for Netapp but all of his Cygwin activities occur on his own time. He is most notably responsible for the support of signal handling and fork/exec in Cygwin. He also administers the site which hosts the Cygwin project.

Corinna Vinschen (corinna) is the other project lead. Corinna is a senior Red Hat engineer. Corinna is responsible for such important subsystems as security and networking and has recently added support to Cygwin for wide characters, increased path length, IPv6, advisory file locking and more.

Yaakov Selkowitz is the Cygwin/X coordinator. Jon Turney serves on the Cygwin/X team as a developer.

The Cygwin setup project is currently maintained by a group of people, most notably, Brian Dessent (brian) and Dave Korn (dave.korn).

Please note that all of us working on Cygwin try to be as responsive as possible and deal with patches and questions as we get them, but realistically we don't have time to answer all of the email that is sent to the main mailing list. Making Net releases of the Win32 tools and helping people on the Net out is not our primary job function, so some email will have to go unanswered.

Many thanks to everyone using the tools for their many contributions in the form of advice, bug reports, and code fixes. Keep them coming!

2. Setting up Cygwin

2.1. What is the recommended installation procedure?
2.2. What about an automated Cygwin installation?
2.3. Does Setup accept command-line arguments?
2.4. Can I install Cygwin without administrator rights?
2.5. Why not install in C:\?
2.6. Can I use Cygwin Setup to get old versions of packages (like gcc-2.95)?
2.7. After upgrading from Cygwin 1.5 to Cygwin 1.7 my user mount points disappeared! How can I get them back?
2.8. Is Cygwin Setup, or one of the packages, infected with a virus?
2.9. My computer hangs when I run Cygwin Setup!
2.10. What packages should I download? Where are 'make', 'gcc', 'vi', etc?
2.11. How do I just get everything?
2.12. How much disk space does Cygwin require?
2.13. How do I know which version I upgraded from?
2.14. What if setup fails?
2.15. My Windows logon name has a space in it, will this cause problems?
2.16. My HOME environment variable is not what I want.
2.17. How do I uninstall individual packages?
2.18. How do I uninstall a Cygwin service?
2.19. How do I uninstall all of Cygwin?
2.20. How do I install snapshots?
2.21. Can Cygwin Setup maintain a ``mirror''?
2.22. How can I make my own portable Cygwin on CD?
2.23. How do I save, restore, delete, or modify the Cygwin information stored in the registry?

2.1.

What is the recommended installation procedure?

There is only one recommended way to install Cygwin, which is to use the GUI installer setup-*.exe. It is flexible and easy to use. You can pick and choose the packages you wish to install, and update them individually. Full source code is available for all packages and tools. More information on using Cygwin Setup may be found at http://cygwin.com/cygwin-ug-net/setup-net.html.

If you do it any other way, you're on your own! If something doesn't work right for you, and it's not covered here or in the latest development snapshot at http://cygwin.com/snapshots/, then by all means report it to the mailing list.

For a searchable list of packages that can be installed with Cygwin, see http://cygwin.com/packages/.

2.2.

What about an automated Cygwin installation?

The Cygwin Setup program is designed to be interactive, but there are a few different ways to automate it. If you are deploying to multiple systems, the best way is to run through a full installation once, saving the entire downloaded package tree. Then, on target systems, run Cygwin Setup as a "Local Install" pointed at your downloaded package tree. You could do this non-interactively with the command line options -q -L -l x:\cygwin-local\, where your downloaded package tree is in x:\cygwin-local\ (see the next FAQ for an explanation of those options.)

For other options, search the mailing lists with terms such as cygwin automated setup or automated cygwin install.

2.3.

Does Setup accept command-line arguments?

Yes, the full listing is written to the setup.log file when you run setup-x86.exe --help or setup-x86_64.exe --help. The current options are:

Command Line Options:
 -D --download                     Download from internet
 -L --local-install                Install from local directory
 -s --site                         Download site
 -O --only-site                    Ignore all sites except for -s
 -R --root                         Root installation directory
 -x --remove-packages              Specify packages to uninstall
 -c --remove-categories            Specify categories to uninstall
 -P --packages                     Specify packages to install
 -C --categories                   Specify entire categories to install
 -p --proxy                        HTTP/FTP proxy (host:port)
 -a --arch                         architecture to install (x86_64 or x86)
 -q --quiet-mode                   Unattended setup mode
 -M --package-manager              Semi-attended chooser-only mode
 -B --no-admin                     Do not check for and enforce running as
                                   Administrator
 -h --help                         print help
 -l --local-package-dir            Local package directory
 -r --no-replaceonreboot           Disable replacing in-use files on next
                                   reboot.
 -X --no-verify                    Don't verify setup.ini signatures
 -n --no-shortcuts                 Disable creation of desktop and start menu
                                   shortcuts
 -N --no-startmenu                 Disable creation of start menu shortcut
 -d --no-desktop                   Disable creation of desktop shortcut
 -K --pubkey                       URL of extra public key file (gpg format)
 -S --sexpr-pubkey                 Extra public key in s-expr format
 -u --untrusted-keys               Use untrusted keys from last-extrakeys
 -U --keep-untrusted-keys          Use untrusted keys and retain all
 -g --upgrade-also                 also upgrade installed packages
 -o --delete-orphans               remove orphaned packages
 -A --disable-buggy-antivirus      Disable known or suspected buggy anti virus
                                   software packages during execution.

2.4.

Can I install Cygwin without administrator rights?

Yes. The default installation requests administrator rights because this allows to set up the Cygwin environment so that all users can start a Cygwin shell out of the box. However, if you don't have administrator rights for your machine, and the admins don't want to install it for you, you can install Cygwin just for yourself by downloading setup-x86.exe (for a 32 bit install) or setup-x86_64.exe (for a 64 bit install) and then start it from the command line or via the "Run..." dialog from the start menu using the --no-admin option, for instance:

  setup-x86.exe --no-admin

2.5.

Why not install in C:\?

The Cygwin Setup program will prompt you for a "root" directory. The default is C:\cygwin, but you can change it. You are urged not to choose something like C:\ (the root directory on the system drive) for your Cygwin root. If you do, then critical Cygwin system directories like etc, lib and bin could easily be corrupted by other (non-Cygwin) applications or packages that use \etc, \lib or \bin. Perhaps there is no conflict now, but who knows what you might install in the future? It's also just good common sense to segregate your Cygwin "filesystems" from the rest of your Windows system disk.

(In the past, there had been genuine bugs that would cause problems for people who installed in C:\, but we believe those are gone now.)

2.6.

Can I use Cygwin Setup to get old versions of packages (like gcc-2.95)?

Cygwin Setup can be used to install any packages that are on a Cygwin mirror, which usually includes one version previous to the current one. The complete list may be searched at http://cygwin.com/packages/. There is no complete archive of older packages. If you have a problem with the current version of a Cygwin package, please report it to the mailing list using the guidelines at http://cygwin.com/problems.html.

That said, if you really need an older package, you may be able to find an outdated or archival mirror by searching the web for an old package version (for example, gcc2-2.95.3-10-src.tar.bz2), but keep in mind that this older version will not be supported by the mailing list and that installing the older version will not help improve Cygwin.

2.7.

After upgrading from Cygwin 1.5 to Cygwin 1.7 my user mount points disappeared! How can I get them back?

When you upgrade an existing older Cygwin installation to Cygwin 1.7, your old system mount points (stored in the HKEY_LOCAL_MACHINE branch of your registry) are read by a script and the /etc/fstab file is generated from these entries. No such automatism exists for the user mount points formerly stored in the HKEY_CURRENT_USER branch of the registry. There's a bash script for your convenience, which creates a user-specific /etc/fstab/${USER} file for you, called /bin/copy-user-registry-fstab. For more information on the new fstab files see the User's Guide at http://cygwin.com/cygwin-ug-net/using.html#mount-table

2.8.

Is Cygwin Setup, or one of the packages, infected with a virus?

Unlikely. Unless you can confirm it, please don't report it to the mailing list. Anti-virus products have been known to detect false positives when extracting compressed tar archives. If this causes problems for you, consider disabling your anti-virus software when running setup. Read the next entry for a fairly safe way to do this.

2.9.

My computer hangs when I run Cygwin Setup!

Both Network Associates (formerly McAfee) and Norton anti-virus products have been reported to "hang" when extracting Cygwin tar archives. If this happens to you, consider disabling your anti-virus software when running Cygwin Setup. The following procedure should be a fairly safe way to do that:

  1. Download setup-x86.exe or setup-x86_64.exe and scan it explicitly.

  2. Turn off the anti-virus software.

  3. Run setup to download and extract all the tar files.

  4. Re-activate your anti-virus software and scan everything in C:\cygwin (or wherever you chose to install), or your entire hard disk if you are paranoid.

This should be safe, but only if Cygwin Setup is not substituted by something malicious, and no mirror has been compromised.

See also http://cygwin.com/faq/faq.html#faq.using.bloda for a list of applications that have been known, at one time or another, to interfere with the normal functioning of Cygwin.

2.10.

What packages should I download? Where are 'make', 'gcc', 'vi', etc?

When using Cygwin Setup for the first time, the default is to install a minimal subset of all available packages. If you want anything beyond that, you will have to select it explicitly. See http://cygwin.com/packages/ for a searchable list of available packages, or use cygcheck -p as described in the Cygwin User's Guide at http://cygwin.com/cygwin-ug-net/using-utils.html#cygcheck.

If you want to build programs, of course you'll need gcc, binutils, make and probably other packages from the ``Devel'' category. Text editors can be found under ``Editors''.

2.11.

How do I just get everything?

Long ago, the default was to install everything, much to the irritation of most users. Now the default is to install only a basic core of packages. Cygwin Setup is designed to make it easy to browse categories and select what you want to install or omit from those categories. It's also easy to install everything:

  1. At the ``Select Packages'' screen, in ``Categories'' view, at the line marked ``All'', click on the word ``default'' so that it changes to ``install''. (Be patient, there is some computing to do at this step. It may take a second or two to register the change.) This tells Setup to install everything, not just what it thinks you should have by default.

  2. Now click on the ``View'' button (twice) until you get to the ``Pending'' view. This shows exactly which packages are about to be downloaded and installed.

This procedure only works for packages that are currently available. There is no way to tell Cygwin Setup to install all packages by default from now on. As new packages become available that would not be installed by default, you have to repeat the above procedure to get them.

In general, a better method (in my opinion), is to:

  1. First download & install all packages that would normally be installed by default. This includes fundamental packages and any updates to what you have already installed. Then...

  2. Run Cygwin Setup again, and apply the above technique to get all new packages that would not be installed by default. You can check the list in the ``Pending'' view before proceeding, in case there's something you really don't want.

  3. In the latest version of Cygwin Setup, if you click the ``View'' button (twice) more, it shows packages not currently installed. You ought to check whether you really want to install everything!

2.12.

How much disk space does Cygwin require?

That depends, obviously, on what you've chosen to download and install. A full installation today is probably larger than 1 GB installed, not including the package archives themselves nor the source code.

After installation, the package archives remain in your ``Local Package Directory''. By default the location of setup-x86{_64}.exe. You may conserve disk space by deleting the subdirectories there. These directories will have very weird looking names, being encoded with their URLs (named ftp%3a%2f...).

Of course, you can keep them around in case you want to reinstall a package. If you want to clean out only the outdated packages, Michael Chase has written a script called clean_setup.pl, available at ftp://cygwin.com/pub/cygwin/unsupported/clean_setup.pl.

2.13.

How do I know which version I upgraded from?

Detailed logs of the most recent Cygwin Setup session can be found in /var/log/setup.log.full and less verbose information about prior actions is in /var/log/setup.log.

2.14.

What if setup fails?

First, make sure that you are using the latest version of Cygwin Setup. The latest version is always available from the Cygwin Home Page at http://cygwin.com/.

If you are downloading from the Internet, setup will fail if it cannot download the list of mirrors at http://cygwin.com/mirrors.html. It could be that the network is too busy. Something similar could be the cause of a download site not working. Try another mirror, or try again later.

If setup refuses to download a package that you know needs to be upgraded, try deleting that package's entry from /etc/setup. If you are reacting quickly to an announcement on the mailing list, it could be that the mirror you are using doesn't have the latest copy yet. Try another mirror, or try again tomorrow.

If setup has otherwise behaved strangely, check the files setup.log and setup.log.full in /var/log (C:\cygwin\var\log by default). It may provide some clues as to what went wrong and why.

If you're still baffled, search the Cygwin mailing list for clues. Others may have the same problem, and a solution may be posted there. If that search proves fruitless, send a query to the Cygwin mailing list. You must provide complete details in your query: version of setup, options you selected, contents of setup.log and setup.log.full, what happened that wasn't supposed to happen, etc.

2.15.

My Windows logon name has a space in it, will this cause problems?

Most definitely yes! UNIX shells (and thus Cygwin) use the space character as a word delimiter. Under certain circumstances, it is possible to get around this with various shell quoting mechanisms, but you are much better off if you can avoid the problem entirely.

You have two choices:

  1. You can rename the user in the Windows User Manager GUI and then run mkpasswd.

  2. You can simply edit the /etc/passwd file and change the Cygwin user name (first field). It's also a good idea to avoid spaces in the home directory.

2.16.

My HOME environment variable is not what I want.

When starting Cygwin from Windows, HOME is determined as follows in order of decreasing priority:

  1. HOME from the Windows environment, translated to POSIX form.

  2. The entry in /etc/passwd

  3. /home/USERNAME

When using Cygwin from the network (telnet, ssh,...), HOME is set from /etc/passwd.

If your HOME is set to a value such as /cygdrive/c, it is likely that it was set in Windows. Start a DOS Command Window and type "set HOME" to verify if this is the case.

Access to shared drives is often restricted when starting from the network, thus Domain users may wish to have a different HOME in the Windows environment (on shared drive) than in /etc/passwd (on local drive). Note that ssh only considers /etc/passwd, disregarding HOME.

2.17.

How do I uninstall individual packages?

Run Cygwin Setup as you would to install packages. In the list of packages to install, browse the relevant category or click on the ``View'' button to get a full listing. Click on the cycle glyph until the action reads ``Uninstall''. Proceed by clicking ``Next''.

2.18.

How do I uninstall a Cygwin service?

  1. List all services you have installed with cygrunsrv -L. If you do not have cygrunsrv installed, skip this FAQ.

  2. Before removing the service, you should stop it with cygrunsrv --stop service_name. If you have inetd configured to run as a standalone service, it will not show up in the list, but cygrunsrv --stop inetd will work to stop it as well.

  3. Lastly, remove the service with cygrunsrv --remove service_name.

2.19.

How do I uninstall all of Cygwin?

Setup has no automatic uninstall facility. The recommended method to remove all of Cygwin is as follows:

  1. If you have any Cygwin services running, remove by repeating the instructions in http://cygwin.com/faq/faq.html#faq.setup.uninstall-service for all services that you installed. Common services that might have been installed are sshd, cron, cygserver, inetd, apache, postgresql, and so on.

  2. Stop the X11 server if it is running, and terminate any Cygwin programs that might be running in the background. Exit the command prompt and ensure that no Cygwin processes remain. Note: If you want to save your mount points for a later reinstall, first save the output of mount -m as described at http://cygwin.com/cygwin-ug-net/using-utils.html#mount.

  3. If you installed cyglsa.dll by running the shell script /usr/bin/cyglsa-config as described in http://cygwin.com/cygwin-ug-net/ntsec.html, then you need to configure Windows to stop using the LSA authentication package. You do so by editing the registry and restoring /HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Lsa/Authentication Packages back to it's original value of msv1_0, and then rebooting.

  4. Delete the Cygwin root folder and all subfolders. If you get an error that an object is in use, then ensure that you've stopped all services and closed all Cygwin programs. If you get a 'Permission Denied' error then you will need to modify the permissions and/or ownership of the files or folders that are causing the error. For example, sometimes files used by system services end up owned by the SYSTEM account and not writable by regular users.

    The quickest way to delete the entire tree if you run into this problem is to change the ownership of all files and folders to your account. To do this in Windows Explorer, right click on the root Cygwin folder, choose Properties, then the Security tab. If you are using Windows XP Home or Simple File Sharing, you will need to boot into Safe Mode to access the Security tab. Select Advanced, then go to the Owner tab and make sure your account is listed as the owner. Select the 'Replace owner on subcontainers and objects' checkbox and press Ok. After Explorer applies the changes you should be able to delete the entire tree in one operation. Note that you can also achieve this in Cygwin by typing chown -R user / or by using other tools such as CACLS.EXE.

  5. Delete the Cygwin shortcuts on the Desktop and Start Menu, and anything left by setup-x86{_64}.exe in the download directory. However, if you plan to reinstall Cygwin it's a good idea to keep your setup-x86{_64}.exe download directory since you can reinstall the packages left in its cache without redownloading them.

  6. If you added Cygwin to your system path, you should remove it unless you plan to reinstall Cygwin to the same location. Similarly, if you set your CYGWIN environment variable system-wide and don't plan to reinstall, you should remove it.

  7. Finally, if you want to be thorough you can delete the registry tree Software\Cygwin under HKEY_LOCAL_MACHINE and/or HKEY_CURRENT_USER. However, if you followed the directions above you will have already removed everything important. Typically only the installation directory has been stored in the registry at all.

2.20.

How do I install snapshots?

First, are you sure you want to do this? Snapshots are risky. They have not been tested. Use them only if there is a feature or bugfix that you need to try, and you are willing to deal with any problems, or at the request of a Cygwin developer.

You cannot use Cygwin Setup to install a snapshot.

First, you will need to download the snapshot from the snapshots page at http://cygwin.com/snapshots/. Note the directory where you saved the snapshot tarball.

Before installing a snapshot, you must first Close all Cygwin applications, including shells and services (e.g., inetd, sshd). You will not be able to replace cygwin1.dll if any Cygwin process is running. You may have to restart Windows to clear the DLL from memory (beware of automatic service startup).

Most of the downloaded snapshot can be installed using tar. Cygwin tar won't be able to update /usr/bin/cygwin1.dll (because it's used by tar itself), but it should succeed with everything else. If you are only installing the DLL snapshot, skip the first tar command. Open a bash shell (it should be the only running Cygwin process) and issue the following commands:

	/bin/tar -C / -xvf /posix/path/to/cygwin-inst-YYYYMMDD.tar.* --exclude=usr/bin/cygwin1.dll
	/bin/tar -C /tmp -xvf /posix/path/to/cygwin-inst-YYYYMMDD.tar.* usr/bin/cygwin1.dll

Exit the bash shell, and use Explorer or the Windows command shell to first rename C:\cygwin\bin\cygwin1.dll to C:\cygwin\bin\cygwin1-prev.dll and then move C:\cygwin\tmp\usr\bin\cygwin1.dll to C:\cygwin\bin\cygwin1.dll (assuming you installed Cygwin in C:\cygwin).

The operative word in trying the snapshots is "trying". If you notice a problem with the snapshot that was not present in the release DLL (what we call a "regression"), please report it to the Cygwin mailing list (see http://cygwin.com/problems.html for problem reporting guidelines). If you wish to go back to the older version of the DLL, again, close all Cygwin processes, delete C:\cygwin\bin\cygwin1.dll, and rename C:\cygwin\bin\cygwin1-prev.dll back to C:\cygwin\bin\cygwin1.dll (again assuming that your "/" is C:\cygwin). To restore the rest of the snapshot files, reinstall the "cygwin" package using Setup.

2.21.

Can Cygwin Setup maintain a ``mirror''?

NO. Cygwin Setup cannot do this for you. Use a tool designed for this purpose. See http://rsync.samba.org/, http://www.gnu.org/software/wget/ for utilities that can do this for you. For more information on setting up a custom Cygwin package server, see the Cygwin Setup homepage at http://sourceware.org/cygwin-apps/setup.html.

2.22.

How can I make my own portable Cygwin on CD?

While some users have successfully done this, for example Indiana University's XLiveCD http://xlivecd.indiana.edu/, there is no easy way to do it. Full instructions for constructing a portable Cygwin on CD by hand can be found on the mailing list at http://www.cygwin.com/ml/cygwin/2003-07/msg01117.html (Thanks to fergus at bonhard dot uklinux dot net for these instructions.) Please note that these instructions are rather old and are referring to the somewhat different setup of a Cygwin 1.5.x release. As soon as somebody set this up for Cygwin 1.7, we might add this information here.

2.23.

How do I save, restore, delete, or modify the Cygwin information stored in the registry?

Since Cygwin 1.7, there's nothing important in the registry anymore, except for the installation directory information stored there for the sake of setup-x86{_64}.exe. There's nothing left to manipulate anymore.

3. Further Resources

3.1. Where's the documentation?
3.2. What Cygwin mailing lists can I join?
3.3. What if I have a problem? (Or: Why won't you/the mailing list answer my questions?)

3.1.

Where's the documentation?

If you have installed Cygwin, you can find lots of documentation in /usr/share/doc/. Some packages have Cygwin specific instructions in a file /usr/share/doc/Cygwin/package_name.README. In addition, many packages ship with standard documentation, which you can find in /usr/share/doc/package_name or by using the man or info tools. (Hint: use cygcheck -l package_name to list what man pages the package includes.) Some older packages still keep their documentation in /usr/doc/ instead of /usr/share/doc/.

There are links to quite a lot of documentation on the main Cygwin project web page, http://cygwin.com/, including this FAQ. Be sure to at least read any 'Release Notes' or 'Readme' or 'read this' links on the main web page, if there are any.

There is a comprehensive Cygwin User's Guide at http://cygwin.com/cygwin-ug-net/cygwin-ug-net.html and an API Reference at http://cygwin.com/cygwin-api/cygwin-api.html.

You can find documentation for the individual GNU tools at http://www.fsf.org/manual/. (You should read GNU manuals from a local mirror, check http://www.fsf.org/server/list-mirrors.html for a list of them.)

3.2.

What Cygwin mailing lists can I join?

Comprehensive information about the Cygwin mailing lists can be found at http://cygwin.com/lists.html.

3.3.

What if I have a problem? (Or: Why won't you/the mailing list answer my questions?)

Comprehensive information about reporting problems with Cygwin can be found at http://cygwin.com/problems.html.

4. Using Cygwin

4.1. Why can't my application locate cygncurses-8.dll? or cygintl-3.dll? or cygreadline6.dll? or ...?
4.2. Why is Cygwin suddenly so slow?
4.3. Why can't my services access network shares?
4.4. How should I set my PATH?
4.5. Bash (or another shell) says "command not found", but it's right there!
4.6. How do I convert between Windows and UNIX paths?
4.7. Why doesn't bash read my .bashrc file on startup?
4.8. How can I get bash filename completion to be case insensitive?
4.9. Can I use paths/filenames containing spaces in them?
4.10. Why can't I cd into a shortcut to a directory?
4.11. I'm having basic problems with find. Why?
4.12. Why doesn't su work?
4.13. Why doesn't man -k, apropos or whatis work?
4.14. Why doesn't chmod work?
4.15. Why doesn't my shell script work?
4.16. How do I print under Cygwin?
4.17. Why don't international (Unicode) characters work?
4.18. My application prints international characters but I only see gray boxes
4.19. Is it OK to have multiple copies of the DLL?
4.20. I read the above but I want to bundle Cygwin with a product, and ship it to customer sites. How can I do this without conflicting with any Cygwin installed by the user?
4.21. Can I bundle Cygwin with my product for free?
4.22. But doesn't that mean that if some application installs an older Cygwin DLL on top of a newer DLL, my application will break?
4.23. Why isn't package XYZ available in Cygwin?
4.24. Why is the Cygwin package of XYZ so out of date?
4.25. How can I access other drives?
4.26. How can I copy and paste into Cygwin console windows?
4.27. What firewall should I use with Cygwin?
4.28. How can I share files between Unix and Windows?
4.29. Is Cygwin case-sensitive??
4.30. What about DOS special filenames?
4.31. When it hangs, how do I get it back?
4.32. Why the weird directory structure?
4.33. How do anti-virus programs like Cygwin?
4.34. Is there a Cygwin port of GNU Emacs?
4.35. Is there a Cygwin port of XEmacs?
4.36. What about NT Emacs?
4.37. Why don't some of my old symlinks work anymore?
4.38. Why don't symlinks work on Samba-mounted filesystems?
4.39. How do I setup sshd in a domain?
4.40. Why do my Tk programs not work anymore?
4.41. Why do I get "Address family not supported" errors when playing with IPv6?
4.42. What applications have been found to interfere with Cygwin?
4.43. How do I fix fork() failures?

4.1.

Why can't my application locate cygncurses-8.dll? or cygintl-3.dll? or cygreadline6.dll? or ...?

Well, something has gone wrong somehow...

To repair the damage, you must run Cygwin Setup again, and re-install the package which provides the missing DLL package.

If you already installed the package at one point, Cygwin Setup won't show the option to install the package by default. In the ``Select packages to install'' dialog, click on the Full/Part button. This lists all packages, even those that are already installed. Scroll down to locate the missing package, for instance libncurses8. Click on the ``cycle'' glyph until it says ``Reinstall''. Continue with the installation.

For a detailed explanation of the general problem, and how to extend it to other missing DLLs and identify their containing packages, see http://cygwin.com/ml/cygwin/2002-01/msg01619.html.

4.2.

Why is Cygwin suddenly so slow?

If suddenly every command takes a very long time, then something is probably attempting to access a network share. You may have the obsolete //c notation in your PATH or startup files. Using //c means to contact the network server c, which will slow things down tremendously if it does not exist.

4.3.

Why can't my services access network shares?

If your service is one of those which switch the user context (sshd, inetd, etc), then it depends on the method used to switch to another user. This problem as well as its solution is described in detail in the Cygwin User's Guide, see http://cygwin.com/cygwin-ug-net/ntsec.html.

Workarounds include using public network share that does not require authentication (for non-critical files), providing your password to a net use command, or running the service as your own user with cygrunsrv -u (see /usr/share/doc/Cygwin/cygrunsrv.README for more information).

4.4.

How should I set my PATH?

This is done for you in the file /etc/profile, which is sourced by bash when you start it from the Desktop or Start Menu shortcut, created by setup.exe. The line is

	PATH="/usr/local/bin:/usr/bin:/bin:$PATH"

Effectively, this prepends /usr/local/bin and /usr/bin to your Windows system path. If you choose to reset your PATH, say in $HOME/.bashrc, or by editing etc/profile directly, then you should follow this rule. You must have /usr/bin in your PATH before any Windows system directories. (And you must not omit the Windows system directories!) Otherwise you will likely encounter all sorts of problems running Cygwin applications.

If you're using another shell than bash (say, tcsh), the mechanism is the same, just the names of the login scripts are different.

4.5.

Bash (or another shell) says "command not found", but it's right there!

If you compile a program, you might find that you can't run it:

	bash$ gcc -o hello hello.c
        bash$ hello
        bash: hello: command not found

Unlike the Windows default behaviour, Unix shells like bash do not look for programs in . (the current directory) by default. You can add . to your PATH (see above), but this is not recommended (at least on UNIX) for security reasons. Just tell bash where to find it, when you type it on the command line:

	bash$ gcc -o hello hello.c
        bash$ ./hello
        Hello World!

4.6.

How do I convert between Windows and UNIX paths?

Use the 'cygpath' utility. Type 'cygpath --help' for information. For example (on my installation):

	bash$ cygpath --windows ~/.bashrc
        D:\starksb\.bashrc
        bash$ cygpath --unix C:/cygwin/bin/ls.exe
        /usr/bin/ls.exe
        bash$ cygpath --unix C:\\cygwin\\bin\\ls.exe
        /usr/bin/ls.exe

Note that bash interprets the backslash '\' as an escape character, so you must type it twice in the bash shell if you want it to be recognized as such.

4.7.

Why doesn't bash read my .bashrc file on startup?

Your .bashrc is read from your home directory specified by the HOME environment variable. It uses /.bashrc if HOME is not set. So you need to set HOME (and the home dir in your /etc/passwd entry) correctly.

4.8.

How can I get bash filename completion to be case insensitive?

Add the following to your ~/.bashrc file:

	shopt -s nocaseglob

and add the following to your ~/.inputrc file:

	set completion-ignore-case on

4.9.

Can I use paths/filenames containing spaces in them?

Cygwin does support spaces in filenames and paths. That said, some utilities that use the library may not, since files don't typically contain spaces in Unix. If you stumble into problems with this, you will need to either fix the utilities or stop using spaces in filenames used by Cygwin tools.

In particular, bash interprets space as a word separator. You would have to quote a filename containing spaces, or escape the space character. For example:

	bash-2.03$ cd '/cygdrive/c/Program Files'

or

	bash-2.03$ cd /cygdrive/c/Program\ Files

4.10.

Why can't I cd into a shortcut to a directory?

Cygwin does not follow MS Windows Explorer Shortcuts (*.lnk files). It sees a shortcut as a regular file and this you cannot "cd" into it.

Cygwin is also capable to create POSIX symlinks as Windows shortcuts (see the CYGWIN environment variable option "winsymlinks"), but these shortcuts are different from shortcuts created by native Windows applications. Windows applications can usually make use of Cygwin shortcuts but not vice versa. This is by choice. The reason is that Windows shortcuts may contain a bunch of extra information which would get lost, if, for example, Cygwin tar archives and extracts them as symlinks.

Changing a Cygwin shortcut in Windows Explorer usually changes a Cygwin shortcut into a Windows native shortcut. Afterwards, Cygwin will not recognize it as symlink anymore.

4.11.

I'm having basic problems with find. Why?

Make sure you are using the find that came with Cygwin and that you aren't picking up the Win32 find command instead. You can verify that you are getting the right one by doing a "type find" in bash.

If the path argument to find, including current directory (default), is itself a symbolic link, then find will not traverse it unless you specify the -follow option. This behavior is different than most other UNIX implementations, but is not likely to change.

If find does not seem to be producing enough results, or seems to be missing out some directories, you may be experiencing a problem with one of find's optimisations. The absence of . and .. directories on some filesystems, such as DVD-R UDF, can confuse find. See the documentation for the option -noleaf in the man page.

4.12.

Why doesn't su work?

The su command has been in and out of Cygwin distributions, but it has not been ported to Cygwin and has never worked. It is currently installed as part of the sh-utils, but again, it does not work.

You should rather install sshd and use ssh username@localhost as a su replacement.

For some technical background into why su doesn't work, read http://www.cygwin.com/ml/cygwin/2003-06/msg00897.html and related messages.

4.13.

Why doesn't man -k, apropos or whatis work?

Before you can use man -k, apropos or whatis, you must create the whatis database. Just run the command

	/usr/sbin/makewhatis

(it may take a minute to complete).

4.14.

Why doesn't chmod work?

The most common case is that your /etc/passwd or /etc/group files are not properly set up. If ls -l shows a group of mkpasswd or mkgroup, you need to run one or both of those commands.

If you're using FAT32 instead of NTFS, chmod will fail since FAT32 does not provide any permission information. You should really consider converting the drive to NTFS with CONVERT.EXE. FAT and FAT32 are barely good enough for memory cards or USB sticks to exchange pictures...

For other cases, understand that Cygwin attempts to show UNIX permissions based on the security features of Windows, so the Windows ACLs are likely the source of your problem. See the Cygwin User's Guide at http://cygwin.com/cygwin-ug-net/ntsec.html for more information on how Cygwin maps Windows permissions.

4.15.

Why doesn't my shell script work?

There are two basic problems you might run into. One is the fact that /bin/sh is really bash. It could be missing some features you might expect in /bin/sh, if you are used to /bin/sh actually being zsh (MacOS X "Panther") or ksh (Tru64).

Or, it could be a permission problem, and Cygwin doesn't understand that your script is executable. On NTFS or NFS just make the script executable using chmod +x. However, chmod may not work due to restrictions of the filesystem (see FAQ entry above). In this case Cygwin must read the contents of files to determine if they are executable. If your script does not start with

	#! /bin/sh

(or any path to a script interpreter, it does not have to be /bin/sh) then Cygwin will not know it is an executable script. The Bourne shell idiom

	:
	# This is the 2nd line, assume processing by /bin/sh

also works.

Note that you can use the filesystem flag cygexec in /etc/fstab to force Cygwin to treat all files under the mount point as executable. This can be used for individual files as well as directories. Then Cygwin will not bother to read files to determine whether they are executable.

4.16.

How do I print under Cygwin?

lpr is available in the cygutils package. Some usage hints are available courtesy of Rodrigo Medina.

Jason Tishler has written a couple of messages that explain how to use a2ps (for nicely formatted text in PostScript) and ghostscript (to print PostScript files on non-PostScript Windows printers). Start at http://cygwin.com/ml/cygwin/2001-04/msg00657.html. Note that the file command is now available as part of Cygwin setup.

Alternatively, you can use the Windows print command. (It does not seem to be available on Win9x.) Type

	bash$ print /\?

for usage instructions (note the ? must be escaped from the shell).

Finally, you can simply cat the file to the printer's share name:

	bash$ cat myfile > //host/printer

You may need to press the formfeed button on your printer or append the formfeed character to your file.

4.17.

Why don't international (Unicode) characters work?

Internationalization is a complex issue. The short answer is that Cygwin relies on the setting of the setting of LANG/LC_xxx environment variables. The long answer can be found in the User's Guide in the section Internationalization

Cygwin uses UTF-8 by default. To use a different character set, you need to set the LC_ALL, LC_CTYPE or LANG environment variables.

4.18.

My application prints international characters but I only see gray boxes

In the case of Cygwin programs, this likely means that the character set as determined by the LC_ALL, LC_CTYPE or LANG environment variables does not match the one set on the Text page of the Cygwin Terminal's options. Setting the locale in the terminal's options will set the LANG variable accordingly.

Non-Cygwin programs in the Cygwin Terminal do not usually take heed of the locale environment variables. Instead, they often use the so-called console codepage, which can be determined with the command cmd /c chcp followed by the appropriate Windows codepage number. The codepage number for Cygwin's default UTF-8 character set is 65001.

4.19.

Is it OK to have multiple copies of the DLL?

Yes, as long as they are used in strictly separated installations.

The Cygwin DLL has to handle various sharing situations between multiple processes. It has to keep a process table. It has to maintain a mount table which is based on the installation path of the Cygwin DLL.

For that reason, the Cygwin DLL maintains shared resources based on a hash value created from its own installation path. Each Cygwin DLL on the machine constitutes a Cygwin installation, with the directory the Cygwin DLL resides in treated as "/bin", the parent directory as "/".

Therefore, you can install two or more separate Cygwin distros on a single machine. Each of these installations use their own Cygwin DLL, and they don't share the default POSIX paths, nor process tables, nor any other shared resource used to maintain the installation.

However, a clean separation requires that you don't try to run executables of one Cygwin installation from processes running in another Cygwin installation. This may or may not work, but the chances that the result is not what you expect are pretty high.

If you get the error "shared region is corrupted" or "shared region version mismatch" it means you have multiple versions of cygwin1.dll running at the same time which conflict with each other. Apart from mixing executables of different Cygwin installations, this could also happen if you have one a single Cygwin installation, for example, if you update the Cygwin package without exiting all Cygwin apps (including services like sshd) beforehand.

The only DLL that is sanctioned by the Cygwin project is the one that you get by running setup.exe, installed in a directory controlled by this program. If you have other versions on your system and desire help from the cygwin project, you should delete or rename all DLLs that are not installed by setup.exe.

If you're trying to find multiple versions of the DLL that are causing this problem, reboot first, in case DLLs still loaded in memory are the cause. Then use the Windows System find utility to search your whole machine, not just components in your PATH (as 'type' would do) or cygwin-mounted filesystems (as Cygwin 'find' would do).

4.20.

I read the above but I want to bundle Cygwin with a product, and ship it to customer sites. How can I do this without conflicting with any Cygwin installed by the user?

Usually, if you keep your installation separate, nothing bad should happen. However, for the user's convenience, and to avoid potential problems which still can occur, consider to integrate your product with an already existing Cygwin installation on the user's machine, or, if there is none, consider to install the official Cygwin distro on behalf of the user and integrate your tools from there. (If you write a tool to make this easy, consider contributing it for others to use)

4.21.

Can I bundle Cygwin with my product for free?

Only if you comply with Cygwin's license very carefully. If you choose to distribute cygwin1.dll, you must be willing to distribute the exact source code used to build that copy of cygwin1.dll as per the terms of the GPL. If you ship applications that link with cygwin1.dll, you must either provide those applications' source code under a GPL-compatible license, *or* purchase a cygwin license from Red Hat.

4.22.

But doesn't that mean that if some application installs an older Cygwin DLL on top of a newer DLL, my application will break?

It depends on what you mean by "break". If the application installs a version of the Cygwin DLL in another location than Cygwin's /bin directory then the rules in Q: 4.20 apply. If the application installs an older version of the DLL in /bin then you should complain loudly to the application provider.

Remember that the Cygwin DLL strives to be backwards compatible so a newer version of the DLL should always work with older executables. So, in general, it is always best to keep one version of the DLL on your system and it should always be the latest version which matches your installed distribution.

4.23.

Why isn't package XYZ available in Cygwin?

Probably because there is nobody willing or able to maintain it. It takes time, and the priority for the Cygwin Team is the Cygwin package. The rest is a volunteer effort. Want to contribute? See http://cygwin.com/setup.html.

4.24.

Why is the Cygwin package of XYZ so out of date?

(Also: Why is the version of package XYZ older than the version that I can download from the XYZ web site? Why is the version of package XYZ older than the version that I installed on my linux system? Is there something special about Cygwin which requires that only an older version of package XYZ will work on it?)

Every package in the Cygwin distribution has a maintainer who is responsible for sending out updates of the package. This person is a volunteer who is rarely the same person as the official developer of the package. If you notice that a version of a package seems to be out of date, the reason is usually pretty simple -- the person who is maintaining the package hasn't gotten around to updating it yet. Rarely, the newer package actually requires complex changes that the maintainer is working out.

If you urgently need an update, sending a polite message to the cygwin mailing list pinging the maintainer is perfectly acceptable. There are no guarantees that the maintainer will have time to update the package or that you'll receive a response to your request, however.

Remember that the operative term here is "volunteer".

4.25.

How can I access other drives?

You have some flexibility here.

Cygwin has a builtin "cygdrive prefix" for drives that are not mounted. You can access any drive, say Z:, as '/cygdrive/z/'.

In some applications (notably bash), you can use the familiar windows <drive>:/path/, using posix forward-slashes ('/') instead of Windows backward-slashes ('\'). (But see the warning below!) This maps in the obvious way to the Windows path, but will be converted internally to use the Cygwin path, following mounts (default or explicit). For example:

	bash$ cd C:/Windows
	bash$ pwd
        /cygdrive/c/Windows

and

	bash$ cd C:/cygwin
	bash$ pwd
        /

for a default setup. You could also use backward-slashes in the Windows path, but these would have to be escaped from the shell.

Warning: There is some ambiguity in going from a Windows path to the posix path, because different posix paths, through different mount points, could map to the same Windows directory. This matters because different mount points may be binmode or textmode, so the behavior of Cygwin apps will vary depending on the posix path used to get there.

You can avoid the ambiguity of Windows paths, and avoid typing "/cygdrive", by explicitly mounting drives to posix paths. For example:

	bash$ mkdir /c
	bash$ mount c:/ /c
	bash$ ls /c

Then /cygdrive/c/Windows becomes /c/Windows which is a little less typing.

Note that you have to enter the mount point into the /etc/fstab file to keep it indefinitely. The mount command will only add the mount point for the lifetime of your current Cygwin session.

You can change the default cygdrive prefix and whether it is binmode or textmode using the /etc/fstab file as well. See the Cygwin User's Guide at http://cygwin.com/cygwin-ug-net/using.html#mount-table for more details.

4.26.

How can I copy and paste into Cygwin console windows?

First, consider using mintty instead of the standard console window. In mintty, selecting with the left-mouse also copies, and middle-mouse pastes. It couldn't be easier!

In Windows's console window, open the properties dialog. The options contain a toggle button, named "Quick edit mode". It must be ON. Save the properties.

You can also bind the insert key to paste from the clipboard by adding the following line to your .inputrc file:

	"\e[2~": paste-from-clipboard 

4.27.

What firewall should I use with Cygwin?

We have had good reports about Kerio Personal Firewall, ZoneLabs Integrity Desktop, and the built-in firewall in Windows XP. Other well-known products including ZoneAlarm and Norton Internet Security have caused problems for some users but work fine for others. At last report, Agnitum Outpost did not work with Cygwin. If you are having strange connection-related problems, disabling the firewall is a good troubleshooting step (as is closing or disabling all other running applications, especially resource-intensive processes such as indexed search).

On the whole, Cygwin doesn't care which firewall is used. The few rare exceptions have to do with socket code. Cygwin uses sockets to implement many of its functions, such as IPC. Some overzealous firewalls install themselves deeply into the winsock stack (with the 'layered service provider' API) and install hooks throughout. Sadly the mailing list archives are littered with examples of poorly written firewall-type software that causes things to break. Note that with many of these products, simply disabling the firewall does not remove these changes; it must be completely uninstalled.

See also http://cygwin.com/faq/faq.html#faq.using.bloda for a list of applications that have been known, at one time or another, to interfere with the normal functioning of Cygwin.

4.28.

How can I share files between Unix and Windows?

During development, we have Linux boxes running Samba and NFS as well as Windows machines. We often build with cross-compilers under Linux and copy binaries and source to the Windows system or just toy with them directly off the Samba-mounted partition. Or, we use the Microsoft NFS client and just use NFS shares on Linux from Windows. And then there are tools like scp, ftp, rsync, ...

4.29.

Is Cygwin case-sensitive??

Several Unix programs expect to be able to use to filenames spelled the same way, but with different case. A prime example of this is perl's configuration script, which wants Makefile and makefile. Windows can't tell the difference between files with just different case, so the configuration fails.

To help with this problem, Cygwin supports case sensitivity starting with Cygwin 1.7.0. For a detailed description how to use that feature see the Cygwin User's Guilde at http://cygwin.com/cygwin-ug-net/using-specialnames.html.

4.30.

What about DOS special filenames?

In Windows, files cannot be named com1, lpt1, or aux (to name a few); either as the root filename or as the extension part. If you do, you'll have trouble. Unix programs don't avoid these names which can make things interesting. E.g., the perl distribution has a file called aux.sh. The perl configuration tries to make sure that aux.sh is there, but an operation on a file with the magic letters 'aux' in it will hang.

At least that's what happens when using native Windows tools. Cygwin 1.7.0 and later can deal with these filenames just fine. Again, see the User's Guide at http://cygwin.com/cygwin-ug-net/using-specialnames.html for a detailed description of what's possible with filenames and what is not.

4.31.

When it hangs, how do I get it back?

If something goes wrong and the tools hang on you for some reason (easy to do if you try and read a file called aux.sh), first try hitting ^C to return to bash or the cmd prompt.

If you start up another shell, and applications don't run, it's a good bet that the hung process is still running somewhere. Use the Task Manager, pview, or a similar utility to kill the process.

And, if all else fails, there's always the reset button/power switch. In theory this should never be necessary, though.

4.32.

Why the weird directory structure?

Why do /lib and /usr/lib (and /bin, /usr/bin) point to the same thing?

Why use mounts instead of symbolic links?

Can I use a disk root (e.g., C:\) as Cygwin root? Why is this discouraged?

After a new installation in the default location, your mount points will look something like this:

	bash$ mount
	C:\cygwin\bin on /usr/bin type ntfs (binary,auto)
	C:\cygwin\lib on /usr/lib type ntfs (binary,auto)
	C:\cygwin on / type ntfs (binary,auto)
	C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)

Note that /bin and /usr/bin point to the same location, as do /lib and /usr/lib. This is intentional, and you should not undo these mounts unless you really know what you are doing.

Various applications and packages may expect to be installed in /lib or /usr/lib (similarly /bin or /usr/bin). Rather than distinguish between them and try to keep track of them (possibly requiring the occasional duplication or symbolic link), it was decided to maintain only one actual directory, with equivalent ways to access it.

Symbolic links had been considered for this purpose, but were dismissed because they do not always work on Samba drives. Also, mounts are faster to process because no disk access is required to resolve them.

Note that non-cygwin applications will not observe Cygwin mounts (or symlinks for that matter). For example, if you use WinZip to unpack the tar distribution of a Cygwin package, it may not get installed to the correct Cygwin path. So don't do this!

It is strongly recommended not to make the Cygwin root directory the same as your drive's root directory, unless you know what you are doing and are prepared to deal with the consequences. It is generally easier to maintain the Cygwin hierarchy if it is isolated from, say, C:\. For one thing, you avoid possible collisions with other (non-cygwin) applications that may create (for example) \bin and \lib directories. (Maybe you have nothing like that installed now, but who knows about things you might add in the future?)

4.33.

How do anti-virus programs like Cygwin?

Users have reported that NAI (formerly McAfee) VirusScan for NT (and others?) is incompatible with Cygwin. This is because it tries to scan the newly loaded shared memory in cygwin1.dll, which can cause fork() to fail, wreaking havoc on many of the tools. (It is not confirmed that this is still a problem, however.)

There have been several reports of NAI VirusScan causing the system to hang when unpacking tar.gz archives. This is surely a bug in VirusScan, and should be reported to NAI. The only workaround is to disable VirusScan when accessing these files. This can be an issue during setup, and is discussed in that FAQ entry.

Some users report a significant performance hit using Cygwin when their anti-virus software is enabled. Rather than disable the anti-virus software completely, it may be possible to specify directories whose contents are exempt from scanning. In a default installation, this would be C:\cygwin\bin. Obviously, this could be exploited by a hostile non-Cygwin program, so do this at your own risk.

See also http://cygwin.com/faq/faq.html#faq.using.bloda for a list of applications that have been known, at one time or another, to interfere with the normal functioning of Cygwin.

4.34.

Is there a Cygwin port of GNU Emacs?

Yes. Install the emacs package. This provides everything you need in order to run GNU emacs in a terminal window. If you also want to be able to use the X11 (http://x.cygwin.com/) GUI, install the emacs-X11 package. In either case, you run emacs by typing 'emacs' or '/usr/bin/emacs'.

4.35.

Is there a Cygwin port of XEmacs?

Yes. It can be used in three different modes:

You have to set the DISPLAY environment variable before starting xemacs.

	bash$ DISPLAY=127.0.0.1:0 xemacs &
  • Windows native GUI

You have to unset the DISPLAY environment variable before starting xemacs.

	bash$ DISPLAY= xemacs &
  • Console mode

Start xemacs with -nw in a terminal (native or X11) window

	bash$ xemacs -nw

The current stable Cygwin version of XEmacs is 21.4.x. But there is also a Cygwin test release version (21.5.x) available for download via setup.exe.

To use all the standard packages with XEmacs you should download the following two packages:

  • xemacs-sumo - XEmacs standard packages

  • xemacs-mule-sumo - XEmacs MULE (MUlti Lingual Emacs) packages

An alternative native distribution of XEmacs for Windows based systems can be downloaded from http://xemacs.org/Download/win32/index.html. It uses an InnoSetup Kit based installer.

4.36.

What about NT Emacs?

If you want GNU Emacs with a native Microsoft GUI interface, then you can either use XEmacs (see above), or native NT Emacs: see section Where can I get pre-compiled versions? in NT Emacs FAQ.

NT Emacs uses the Windows command shell by default. Since it is not a Cygwin application, it has no knowledge of Cygwin mounts. With those points in mind, you need to add the following code to your ~/.emacs (or ~/_emacs) file in order to use Cygwin bash. This is particularly useful for the JDEE package (http://jdee.sunsite.dk/). The following settings are for Emacs 21.1:


	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; Initial setup
	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	;; This assumes that Cygwin is installed in C:\cygwin (the
	;; default) and that C:\cygwin\bin is not already in your
	;; Windows Path (it generally should not be).

	(setq exec-path (cons "C:/cygwin/bin" exec-path))
	(setenv "PATH" (concat "C:\\cygwin\\bin;" (getenv "PATH")))

	;;   LOGNAME and USER are expected in many Emacs packages
	;;   Check these environment variables.

	(if (and (null (getenv "USER"))
		 ;; Windows includes variable USERNAME, which is copied to
		 ;; LOGNAME and USER respectively.
		 (getenv "USERNAME"))
	    (setenv "USER" (getenv "USERNAME")))

	(if (and (getenv "LOGNAME")
		 ;;  Bash shell defines only LOGNAME
		 (null (getenv "USER")))
	    (setenv "USER" (getenv "LOGNAME")))

	(if (and (getenv "USER")
		 (null (getenv "LOGNAME")))
	    (setenv "LOGNAME" (getenv "USER")))

	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; (A) M-x shell: This change M-x shell permanently
	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	;; Would call Windows command interpreter. Change it.

	(setq shell-file-name "bash")
	(setenv "SHELL" shell-file-name)
	(setq explicit-shell-file-name shell-file-name)

	;; Remove C-m (^M) characters that appear in output

	(add-hook 'comint-output-filter-functions
	          'comint-strip-ctrl-m)

	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; (B) *OR* call following function with M-x my-bash
	;; The M-x shell would continue to run standard Windows shell
	;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	(defun my-bash (&optional buffer)
	  "Run Cygwin Bash shell in optional BUFFER; default *shell-bash*."
	  (autoload 'comint-check-proc "comint")
	  (interactive
	   (let ((name "*shell-bash*"))
	     (if current-prefix-arg
		 (setq name (read-string
			     (format "Cygwin shell buffer (default %s): " name)
			     (not 'initial-input)
			     (not 'history)
			     name)))
	     (list name)))
	  (or buffer
	      (setq buffer "*shell-bash*"))
	  (if (comint-check-proc buffer)
	      (pop-to-buffer buffer)
	    (let* ((shell-file-name            "bash")
		   (explicit-shell-file-name   shell-file-name)
		   (explicit-sh-args           '("--login" "-i"))
		   (explicit-bash-args         explicit-sh-args)
		   (w32-quote-process-args     ?\"));; Use Cygwin quoting rules.
	      (shell buffer)
	      ;;  By default Emacs sends "\r\n", but bash wants plain "\n"
	      (set-buffer-process-coding-system 'undecided-dos 'undecided-unix)
	      ;; With TAB completion, add slash path separator, none to filenames
	      (make-local-variable 'comint-completion-addsuffix)
	      (setq comint-completion-addsuffix '("/" . ""))
	      ;;  This variable is local to buffer
	      (setq comint-prompt-regexp "^[ \n\t]*[$] ?"))))

If you want NT Emacs to understand Cygwin paths, get cygwin-mount.el from http://www.emacswiki.org/elisp/index.html.

Note that all of this ``just works'' if you use the Cygwin port of Emacs or XEmacs from Cygwin Setup.

4.37.

Why don't some of my old symlinks work anymore?

Beginning with Cygwin 1.7, Cygwin supports multiple character sets. Symlinks created with Cygwin 1.7 are using the UTF-16 character set, which is portable across all character sets. Old symlinks were written using your current Windows codepage, which is not portable across all character sets. If the target of the symlink doesn't resolve anymore, it's very likely that the symlink points to a target filename using native, non-ASCII characters, and you're now using another character set than way back when you created the symlink.

Solution: Delete the symlink and create it again under you new Cygwin. The new symlink will be correctly point to the target no matter what character set you're using in future.

4.38.

Why don't symlinks work on Samba-mounted filesystems?

Symlinks are marked with "system" file attribute. Samba does not enable this attribute by default. To enable it, consult your Samba documentation and then add these lines to your samba configuration file:

	map system = yes
	create mask = 0775

Note that the 0775 can be anything as long as the 0010 bit is set.

Alternatively, use Windows shortcuts as symlinks. See the CYGWIN environment variable option "winsymlinks" http://cygwin.com/cygwin-ug-net/using-cygwinenv.html

4.39.

How do I setup sshd in a domain?

If you want to be able to logon with domain accounts to a domain member machine, you should make sure that the "cyg_server" account under which the sshd service is usually running, is a domain account. Otherwise you might end up with weird problems. For instance, sshd might fail to load the child process when trying to login with a domain account. A potential, confirmed error message is

  *** fatal error - unable to load user32.dll, Win32 error 1114

Here's how you set up a sshd with a domain service account.

First of all, create a new domain account called "cyg_server". This account must be an administrative account, so make sure it's in the "Administrators" group. Now create a domain policy which is propagated to all machines which are supposed to run an sshd service. This domain policy should give the following user rights to the "cyg_server" account:

  Act as part of the operating system (SeTcbPrivilege)
  Create a token object               (SeCreateTokenPrivilege)
  Replace a process level token       (SeAssignPrimaryTokenPrivilege)

Now to install sshd on the member machine, logon to that machine as an admin. Make sure the aforementioend global policy has been propagated to this machine. Examine the Local Security Policy settings and, if necessary, call gpupdate.

If everything looks ok, run bash. Starting with Windows Vista, make sure you're running bash elevated.

If "cyg_server" is not already in /etc/passwd, add it using mkpasswd. Make sure all domain accounts which are supposed to be able to logon via ssh are in /etc/passwd. Also make sure that all important domain groups are in /etc/group. If in doubt, call

  $ mkpasswd -l -d your_domain > /etc/passwd
  $ mkgroup -l -d your_domain > /etc/group

Then run ssh-host-config. Answer all questions so that "cyg_server" is used to run the service. When done, check ownership of /var/empty and all /etc/ssh* files. All of them must be owned by "cyg_server". If that's ok, you're usually all set and you can start the sshd service via

  $ cygrunsrv -S sshd

or

  $ net start sshd

4.40.

Why do my Tk programs not work anymore?

Previous versions of Tcl/Tk distributed with Cygwin (e.g. tclsh84.exe, wish84.exe) were not actually "Cygwin versions" of those tools. They were built as native libraries, which means they did not understand Cygwin mounts or symbolic links. This lead to all sorts of problems interacting with true Cygwin programs.

As of February 2012, this was replaced with a version of Tcl/Tk which uses Cygwin's POSIX APIs and X11 for GUI functionality. If you get a message such as this when trying to start a Tk app:

  Application initialization failed: couldn't connect to display ""

Then you need to start an X server, or if one is already running, set the DISPLAY variable to the proper value. The Cygwin distribution includes an X server; please see the Cygwin/X User Guide for installation and startup instructions.

4.41.

Why do I get "Address family not supported" errors when playing with IPv6?

IPv6 is only fully supported and available right from the start beginning with Windows Vista and Windows Server 2008.

The previous generation of Windows, Windows XP and Windows Server 2003, only support IPv6 on an "experimental" basis. On these Windows versions, the IPv6 TCP/IP stack is not installed automatically, rather the system administrator has to install it manually. Unless this has already been done on your machine, your machine is not IPv6-capable and that's why you see the "Address family not supported" error message. Note, however, that the IPv6 stack on these systems don't fully support all features of IPv6.

For more information about IPv6 on Windows and how to install the IPv6 stack, see the Microsoft TechNet IPv6 FAQ article

4.42.

What applications have been found to interfere with Cygwin?

From time to time, people have reported strange failures and problems in Cygwin and Cygwin packages that seem to have no rational explanation. Among the most common symptoms they report are fork failures, memory leaks, and file access denied problems. These problems, when they have been traced, often appear to be caused by interference from other software installed on the same PC. Security software, in particular, such as anti-virus, anti-spyware, and firewall applications, often implements its functions by installing hooks into various parts of the system, including both the Explorer shell and the underlying kernel. Sometimes these hooks are not implemented in an entirely transparent fashion, and cause changes in the behaviour which affect the operation of other programs, such as Cygwin.

Among the software that has been found to cause difficulties are:

  • Sonic Solutions burning software containing DLA component (when DLA disabled)

  • Norton/McAfee/Symantec antivirus or antispyware

  • Logitech webcam software with "Logitech process monitor" service

  • Kerio, Agnitum or ZoneAlarm Personal Firewall

  • Iolo System Mechanic/AntiVirus/Firewall

  • LanDesk

  • Windows Defender

  • Various programs by Wave Systems Corp using wxvault.dll, including Embassy Trust Suite and Embassy Security Center

  • NOD32 Antivirus

  • ByteMobile laptop optimization client

  • Earthlink Total-Access

  • Spybot S&D TeaTimer

  • AR Soft RAM Disk

  • ATI Catalyst (some versions)

  • NVIDIA GeForce (some versions)

  • Windows LiveOneCare

  • Webroot Spy Sweeper with Antivirus

  • COMODO Firewall Pro

  • PC Tools Spyware Doctor

  • Avira AntiVir

  • Panda Internet Security

  • BitDefender

  • Google Desktop

  • Sophos Anti-Virus 7

  • Bufferzone from Trustware

  • Lenovo IPS Core Service (ipssvc)

  • Credant Guardian Shield

  • AVAST (disable FILESYSTEM and BEHAVIOR realtime shields)

  • Citrix Metaframe Presentation Server/XenApp (see Citrix Support page)

Sometimes these problems can be worked around, by temporarily or partially disabling the offending software. For instance, it may be possible to disable on-access scanning in your antivirus, or configure it to ignore files under the Cygwin installation root. Often, unfortunately, this is not possible; even disabling the software may not work, since many applications that hook the operating system leave their hooks installed when disabled, and simply set them into what is intended to be a completely transparent pass-through mode. Sometimes this pass-through is not as transparent as all that, and the hooks still interfere with Cygwin; in these cases, it may be necessary to uninstall the software altogether to restore normal operation.

Some of the symptoms you may experience are:

  • Random fork() failures.

    Caused by hook DLLs that load themselves into every process in the system. POSIX fork() semantics require that the memory map of the child process must be an exact duplicate of the parent process' layout. If one of these DLLs loads itself at a different base address in the child's memory space as compared to the address it was loaded at in the parent, it can end up taking the space that belonged to a different DLL in the parent. When Cygwin can't load the original DLL at that same address in the child, the fork() call has to fail.

  • File access problems.

    Some programs (e.g., virus scanners with on-access scanning) scan or otherwise operate on every file accessed by all the other software running on your computer. In some cases they may retain an open handle on the file even after the software that is really using the file has closed it. This has been known to cause operations such as deletes, renames and moves to fail with access denied errors. In extreme cases it has been known for scanners to leak file handles, leading to kernel memory starvation.

  • Networking issues

    Firewall software sometimes gets a bit funny about Cygwin. It's not currently understood why; Cygwin only uses the standard Winsock2 API, but perhaps in some less-commonly used fashion that doesn't get as well tested by the publishers of firewalls. Symptoms include mysterious failures to connect, or corruption of network data being sent or received.

  • Memory and/or handle leaks

    Some applications that hook into the Windows operating system exhibit bugs when interacting with Cygwin that cause them to leak allocated memory or other system resources. Symptoms include complaints about out-of-memory errors and even virtual memory exhaustion dialog boxes from the O/S; it is often possible to see the excess memory allocation using a tool such as Task Manager or Sysinternals' Process Explorer, although interpreting the statistics they present is not always straightforward owing to complications such as virtual memory paging and file caching.

4.43.

How do I fix fork() failures?

Unfortunately, Windows does not use the fork/exec model of process creation found in UNIX-like OSes, so it is difficult for Cygwin to implement a reliable and correct fork(), which can lead to error messages such as:

  • unable to remap somedll to same address as parent
  • couldn't allocate heap
  • died waiting for dll loading
  • child -1 - died waiting for longjmp before initialization
  • STATUS_ACCESS_VIOLATION
  • resource temporarily unavailable

Potential solutions for the above errors:

  • Restart whatever process is trying (and failing) to use fork(). Sometimes Windows sets up a process environment that is even more hostile to fork() than usual.
  • Ensure that you have eliminated (not just disabled) all software on the BLODA.
  • Read the 'rebase' package README in /usr/share/doc/rebase/, and follow the instructions there to run 'rebaseall'.

Please note that installing new packages or updating existing ones undoes the effects of rebaseall and often causes fork() failures to reappear. If so, just run rebaseall again.

See the process creation section of the User's Guide for the technical reasons it is so difficult to make fork() work reliably.

5. Cygwin API Questions

5.1. How does everything work?
5.2. Are development snapshots for the Cygwin library available?
5.3. How is the DOS/Unix CR/LF thing handled?
5.4. Is the Cygwin library multi-thread-safe?
5.5. How is fork() implemented?
5.6. How does wildcarding (globbing) work?
5.7. How do symbolic links work?
5.8. Why do some files, which are not executables have the 'x' type.
5.9. How secure is Cygwin in a multi-user environment?
5.10. How do the net-related functions work?
5.11. I don't want Unix sockets, how do I use normal Win32 winsock?
5.12. What version numbers are associated with Cygwin?
5.13. Why isn't timezone set correctly?
5.14. Is there a mouse interface?

5.1.

How does everything work?

There's a C library which provides a POSIX-style API. The applications are linked with it and voila - they run on Windows.

The aim is to add all the goop necessary to make your apps run on Windows into the C library. Then your apps should (ideally) run on POSIX systems (Unix/Linux) and Windows with no changes at the source level.

The C library is in a DLL, which makes basic applications quite small. And it allows relatively easy upgrades to the Win32/POSIX translation layer, providing that DLL changes stay backward-compatible.

For a good overview of Cygwin, you may want to read the Cygwin User's Guide.

5.2.

Are development snapshots for the Cygwin library available?

Yes. They're made whenever anything interesting happens inside the Cygwin library (usually roughly on a nightly basis, depending on how much is going on). They are only intended for those people who wish to contribute code to the project. If you aren't going to be happy debugging problems in a buggy snapshot, avoid these and wait for a real release. The snapshots are available from http://cygwin.com/snapshots/.

5.3.

How is the DOS/Unix CR/LF thing handled?

Let's start with some background.

On POSIX systems, a file is a file and what the file contains is whatever the program/programmer/user told it to put into it. In Windows, a file is also a file and what the file contains depends not only on the program/programmer/user but also the file processing mode.

When processing in text mode, certain values of data are treated specially. A \n (new line, NL) written to the file will prepend a \r (carriage return, CR) so that if you `printf("Hello\n") you in fact get "Hello\r\n". Upon reading this combination, the \r is removed and the number of bytes returned by the read is 1 less than was actually read. This tends to confuse programs dependent on ftell() and fseek(). A Ctrl-Z encountered while reading a file sets the End Of File flags even though it truly isn't the end of file.

One of Cygwin's goals is to make it possible to mix Cygwin-ported POSIX programs with generic Windows programs. As a result, Cygwin allows to open files in text mode. In the accompanying tools, tools that deal with binaries (e.g. objdump) operate in POSIX binary mode and many (but not all) tools that deal with text files (e.g. bash) operate in text mode. There are also some text tools which operate in a mixed mode. They read files always in text mode, but write files in binary mode, or they write in the mode (text or binary) which is specified by the underlying mount point. For a description of mount points, see the Cygwin User's Guide.

Actually there's no really good reason to do text mode processing since it only slows down reading and writing files. Additionally many Windows applications can deal with POSIX \n line endings just fine (unfortunate exception: Notepad). So we suggest to use binary mode as much as possible and only convert files from or to DOS text mode using tools specifically created to do that job, for instance, d2u and u2d from the cygutils package.

It is rather easy for the porter of a Unix package to fix the source code by supplying the appropriate file processing mode switches to the open/fopen functions. Treat all text files as text and treat all binary files as binary. To be specific, you can select binary mode by adding O_BINARY to the second argument of an open call, or "b" to second argument of an fopen call. You can also call setmode (fd, O_BINARY). To select text mode add O_TEXT to the second argument of an open call, or "t" to second argument of an fopen call, or just call setmode (fd, O_TEXT).

You can also avoid to change the source code at all by linking an additional object file to your executable. Cygwin provides various object files in the /usr/lib directory which, when linked to an executable, changes the default open modes of any file opened within the executed process itself. The files are

  binmode.o      - Open all files in binary mode.
  textmode.o     - Open all files in text mode.
  textreadmode.o - Open all files opened for reading in text mode.
  automode.o     - Open all files opened for reading in text mode,
                   all files opened for writing in binary mode.

Note

Linking against these object files does not change the open mode of files propagated to a process by its parent process, for instance, if the process is part of a shell pipe expression.

Note that of the above flags only the "b" fopen flags are defined by ANSI. They exist under most flavors of Unix. However, using O_BINARY, O_TEXT, or the "t" flag is non-portable.

5.4.

Is the Cygwin library multi-thread-safe?

Yes.

There is also extensive support for 'POSIX threads', see the file cygwin.din for the list of POSIX thread functions provided.

5.5.

How is fork() implemented?

Cygwin fork() essentially works like a non-copy on write version of fork() (like old Unix versions used to do). Because of this it can be a little slow. In most cases, you are better off using the spawn family of calls if possible.

Here's how it works:

Parent initializes a space in the Cygwin process table for child. Parent creates child suspended using Win32 CreateProcess call, giving the same path it was invoked with itself. Parent calls setjmp to save its own context and then sets a pointer to this in the Cygwin shared memory area (shared among all Cygwin tasks). Parent fills in the child's .data and .bss subsections by copying from its own address space into the suspended child's address space. Parent then starts the child. Parent waits on mutex for child to get to safe point. Child starts and discovers if has been forked and then longjumps using the saved jump buffer. Child sets mutex parent is waiting on and then blocks on another mutex waiting for parent to fill in its stack and heap. Parent notices child is in safe area, copies stack and heap from itself into child, releases the mutex the child is waiting on and returns from the fork call. Child wakes from blocking on mutex, recreates any mmapped areas passed to it via shared area and then returns from fork itself.

5.6.

How does wildcarding (globbing) work?

If the DLL thinks it was invoked from a DOS style prompt, it runs a `globber' over the arguments provided on the command line. This means that if you type LS *.EXE from DOS, it will do what you might expect.

Beware: globbing uses malloc. If your application defines malloc, that will get used. This may do horrible things to you.

5.7.

How do symbolic links work?

Cygwin knows of two ways to create symlinks.

The default method generates link files with a magic header. When you open a file or directory that is a link to somewhere else, it opens the file or directory listed in the magic header. Because we don't want to have to open every referenced file to check symlink status, Cygwin marks symlinks with the system attribute. Files without the system attribute are not checked. Because remote samba filesystems do not enable the system attribute by default, symlinks do not work on network drives unless you explicitly enable this attribute or use the second method to create symlinks.

The second method is enabled if `winsymlinks' is set in the environment variable CYGWIN. Using this method, Cygwin generates symlinks by creating Windows shortcuts. Cygwin created shortcuts have a special header (which is in that way never created by Explorer) and the R/O attribute set. A DOS path is stored in the shortcut as usual and the description entry is used to store the POSIX path. While the POSIX path is stored as is, the DOS path has perhaps to be rearranged to result in a valid path. This may result in a divergence between the DOS and the POSIX path when symlinks are moved crossing mount points. When a user changes the shortcut, this will be detected by Cygwin and it will only use the DOS path then. While Cygwin shortcuts are shown without the ".lnk" suffix in `ls' output, non-Cygwin shortcuts are shown with the suffix. However, both are treated as symlinks.

Both, types of symlinks can live peacefully together since Cygwin treats both as symlinks regardless of the setting of `(no)winsymlinks' in the environment variable CYGWIN.

5.8.

Why do some files, which are not executables have the 'x' type.

When working out the POSIX-style attribute bits on a file stored on certain filesystems (FAT, FAT32), the library has to fill out some information not provided by these filesystems.

It guesses that files ending in .exe and .bat are executable, as are ones which have a "#!" as their first characters. This guessing doesn't take place on filesystems providing real permission information (NTFS, NFS), unless you switch the permission handling off using the mount flag "noacl" on these filesystems.

5.9.

How secure is Cygwin in a multi-user environment?

As of version 1.5.13, the Cygwin developers are not aware of any feature in the cygwin dll that would allow users to gain privileges or to access objects to which they have no rights under Windows. However there is no guarantee that Cygwin is as secure as the Windows it runs on. Cygwin processes share some variables and are thus easier targets of denial of service type of attacks.

5.10.

How do the net-related functions work?

The network support in Cygwin is supposed to provide the POSIX API, not the Winsock API.

There are differences between the semantics of functions with the same name under the API.

E.g., the POSIX select system call can wait on a standard file handles and handles to sockets. The select call in Winsock can only wait on sockets. Because of this, the Cygwin dll does a lot of nasty stuff behind the scenes, trying to persuade various Winsock/Win32 functions to do what a Unix select would do.

If you are porting an application which already uses Winsock, then porting the application to Cygwin means to port the application to using the POSIX net functions. You should never mix Cygwin net functions with direct calls to Winsock functions. If you use Cygwin, use the POSIX API.

5.11.

I don't want Unix sockets, how do I use normal Win32 winsock?

You don't. Look for the MingW project to port applications using native Win32/Winsock functions.

5.12.

What version numbers are associated with Cygwin?

Cygwin versioning is relatively complicated because of its status as a shared library. First of all, since October 1998 every Cygwin DLL has been named cygwin1.dll and has a 1 in the release name. Additionally, there are DLL major and minor numbers that correspond to the name of the release, and a release number. In other words, cygwin-1.7.1-2 is cygwin1.dll, major version 7, minor version 1, release 2.

The cygwin1.dll major version number gets incremented only when a change is made that makes existing software incompatible. For example, the first major version 5 release, cygwin-1.5.0-1, added 64-bit file I/O operations, which required many libraries to be recompiled and relinked. The minor version changes every time we make a new backward compatible Cygwin release available. There is also a cygwin1.dll release version number. The release number is only incremented if we update an existing release in a way that does not effect the DLL (like a missing header file).

There are also Cygwin API major and minor numbers. The major number tracks important non-backward-compatible interface changes to the API. An executable linked with an earlier major number will not be compatible with the latest DLL. The minor number tracks significant API additions or changes that will not break older executables but may be required by newly compiled ones.

Then there is a shared memory region compatibility version number. It is incremented when incompatible changes are made to the shared memory region or to any named shared mutexes, semaphores, etc. For more exciting Cygwin version number details, check out the /usr/include/cygwin/version.h file.

5.13.

Why isn't timezone set correctly?

(Please note: This section has not yet been updated for the latest net release.)

Did you explicitly call tzset() before checking the value of timezone? If not, you must do so.

5.14.

Is there a mouse interface?

If you're using X then use the X API to handle mouse events. In a Windows console window you can enable and capture mouse events using the xterm escape sequences for mouse events.

6. Programming Questions

6.1. How do I contribute a package?
6.2. How do I contribute to Cygwin?
6.3. Why are compiled executables so huge?!?
6.4. What do I have to look out for when porting applications to 64 bit Cygwin?
6.5. My project doesn't build at all on 64 bit Cygwin. What's up?
6.6. Why is __CYGWIN64__ not defined for 64 bit?
6.7. Where is glibc?
6.8. Where is Objective C?
6.9. Why does my make fail on Cygwin with an execvp error?
6.10. How can I use IPC, or why do I get a Bad system call error?
6.11. Why the undefined reference to WinMain@16?
6.12. How do I use Win32 API calls?
6.13. How do I compile a Win32 executable that doesn't use Cygwin?
6.14. Can I build a Cygwin program that does not require cygwin1.dll at runtime?
6.15. Can I link with both MSVCRT*.DLL and cygwin1.dll?
6.16. How do I make the console window go away?
6.17. Why does make complain about a "missing separator"?
6.18. Why can't we redistribute Microsoft's Win32 headers?
6.19. How do I use cygwin1.dll with Visual Studio or MinGW?
6.20. How do I link against a .lib file?
6.21. How do I build Cygwin on my own?
6.22. I may have found a bug in Cygwin, how can I debug it (the symbols in gdb look funny)?
6.23. How can I compile Cygwin for an unsupported platform (PowerPC, Alpha, ARM, Itanium)?
6.24. How can I adjust the heap/stack size of an application?
6.25. How can I find out which DLLs are needed by an executable?
6.26. How do I build a DLL?
6.27. How can I set a breakpoint at MainCRTStartup?
6.28. How can I build a relocatable dll?
6.29. How can I debug what's going on?
6.30. Can I use a system trace mechanism instead?
6.31. Why doesn't gdb handle signals?
6.32. The linker complains that it can't find something.
6.33. Why do I get an error using struct stat64?
6.34. Can you make DLLs that are linked against libc ?
6.35. Where is malloc.h?
6.36. Can I use my own malloc?
6.37. Can I mix objects compiled with msvc++ and gcc?
6.38. Can I use the gdb debugger to debug programs built by VC++?
6.39. Shell scripts aren't running properly from my makefiles?
6.40. What preprocessor macros do I need to know about?
6.41. How should I port my Unix GUI to Windows?

6.1.

How do I contribute a package?

If you are willing to be a package maintainer, great! We urgently need volunteers to prepare and maintain packages, because the priority of the Cygwin Team is Cygwin itself.

The Cygwin Package Contributor's Guide at http://cygwin.com/setup.html details everything you need to know about being a package maintainer. The quickest way to get started is to read the Initial packaging procedure, script-based section on that page. The generic-build-script found there works well for most packages.

For questions about package maintenance, use the cygwin-apps mailing list (start at http://cygwin.com/lists.html) after searching and browsing the cygwin-apps list archives, of course. Be sure to look at the Submitting a package checklist at http://cygwin.com/setup.html before sending an ITP (Intent To Package) email to cygwin-apps.

You should also announce your intentions to the general cygwin list, in case others were thinking the same thing.

6.2.

How do I contribute to Cygwin?

If you want to contribute to Cygwin itself, see http://cygwin.com/contrib.html.

6.3.

Why are compiled executables so huge?!?

By default, gcc compiles in all symbols. You'll also find that gcc creates large executables on UNIX.

If that bothers you, just use the 'strip' program, part of the binutils package. Or compile with the -s option to gcc.

6.4.

What do I have to look out for when porting applications to 64 bit Cygwin?

The Cygwin x86_64 toolchain is using the LP64 data model. That means, in contrast to Windows, which uses an LLP64 data model, sizeof(long) != sizeof(int), just as on Linux.

For comparison:

                 Cygwin   Windows  Cygwin
                 Linux    x86_64   Linux
                 Windows           x86_64
                 i686

sizeof(int)         4        4        4
sizeof(long)        4        4        8
sizeof(size_t)      4        8        8
sizeof(void*)       4        8        8

This difference can result in interesting problems, especially when using Win32 functions, especially when using pointers to Windows datatypes like LONG, ULONG, DWORD. Given that Windows is LLP64, all of the aforementioned types are 4 byte in size, on 32 as well as on 64 bit Windows, while `long' on 64 bit Cygwin is 8 bytes.

Take the example ReadFile:

  ReadFile (HANDLE, LPVOID, DWORD, LPDWORD, LPOVERLAPPED);

In the 32 bit Cygwin and Mingw environments, as well as in the 64 bit Mingw environment, it is no problem to substitute DWORD with unsigned long:

  unsigned long number_of_bytes_read;
  [...]
  ReadFile (fhdl, buf, buflen, &number_of_bytes_read, NULL);

However, in 64 bit Cygwin, using LP64, number_of_bytes_read is 8 bytes in size. But since ReadFile expects a pointer to a 4 byte type, the function will only change the lower 4 bytes of number_of_bytes_read on return, while the content of the upper 4 bytes stays undefined.

Here are a few donts which should help porting applications from the known ILP32 data model of 32 bit Cygwin, to the LP64 data model of 64 bit Cygwin. Note that these are not Cygwin-only problems. Many Linux applications suffered the same somewhat liberal handling of datatypes when the AMD64 CPU was new.

  • Don't mix up int and long in printf/scanf. This:

        int i; long l;
        printf ("%d %ld\n", l, i);
    

    may not print what you think it should. Enable the gcc options -Wformat or -Wall, which warn about type mismatches in printf/scanf functions.

    Note

    Using -Wall (optionally with -Werror to drive the point home) makes a lot of sense in general, not only when porting code to a new platform.

  • Don't mix int and long pointers.

        long *long_ptr = (long *) &my_int; /* Uh oh! */
        *long_ptr = 42;
    

    The assignment will write 8 bytes to the address of my_int. Since my_int is only 4 bytes, something else gets randomly overwritten. Finding this kind of bug is very hard, because you will often see a problem which has no immediate connection to the actual bug.

  • Don't mix int and pointers at all! This will not work as expected anymore:

        void *ptr;
        printf ("Pointer value is %x\n", ptr);
    

    %x denotes an int argument. The value printed by printf is a 4 byte value, so on x86_64 the printed pointer value is missing its upper 4 bytes; the output is very likely wrong. Use %p instead, which portable across architectures:

        void *ptr;
        printf ("Pointer value is %p\n", ptr);
    

  • Along the same lines don't use the type int in pointer arithmetic. Don't cast pointers to int, don't cast pointer differences to int, and don't store pointer differences in an int type. Use the types intptr_t, uintptr_t and ptrdiff_t instead, they are designed for performing architecture-independent pointer arithmetic.

  • Don't make blind assumptions about the size of a POSIX type. For instance, time_t is 8 bytes on 64 bit Cygwin, while it is (still, at the time of writing this) 4 bytes on 32 bit Cygwin, since time_t is based on the type long.

  • Don't use functions returning pointers without declaration. For instance

        printf ("Error message is: %s\n", strerror (errno));
    

    This code will crash, unless you included string.h. The implicit rule in C is that an undeclared function is of type int. But int is 4 byte and pointers are 8 byte, so the string pointer given to printf is missing the upper 4 bytes.

  • Don't use C base types together with Win32 functions. Keep in mind that DWORD, LONG, ULONG are not the same as long and unsigned long. Try to use only Win32 datatypes in conjunction with Win32 API function calls to avoid type problems. See the above ReadFile example. Windows functions in printf calls should be treated carefully as well. This code is common for 32 bit code, but probably prints the wrong value on 64 bit:

        printf ("Error message is: %lu\n", GetLastError ());
    

    Using gcc's -Wformat option would warn about this. Casting to the requested base type helps in this case:

        printf ("Error message is: %lu\n", (unsigned long) GetLastError ());
    

  • Don't mix Windows datatypes with POSIX type-specific MIN/MAX values.

        unsigned long l_max = ULONG_MAX;    /* That's right. */
        ULONG w32_biggest = ULONG_MAX;	/* Hey, wait!  What? */
        ULONG w32_biggest = UINT_MAX;	/* Ok, but borderline. */
    

    Again, keep in mind that ULONG (or DWORD) is not unsigned long but rather unsigned int on 64 bit.

6.5.

My project doesn't build at all on 64 bit Cygwin. What's up?

Typically reasons for that are:

  • __CYGWIN32__ is not defined in the 64 bit toolchain. This may hit a few projects which are around since before Y2K. Check your project for occurences of __CYGWIN32__ and change them to __CYGWIN__, which is defined in the Cygwin toolchain since 1998, to get the same Cygwin-specific code changes done.

  • The project maintainers took it for granted that Cygwin is running only on i686 CPUs and the code is making this assumption blindly. You have to check the code for such assumptions and fix them.

  • The project is using autotools, the config.sub and config.guess files are hopelessly outdated and don't recognize x86_64-{pc,unknown}-cygwin as valid target. Update the project configury (cygport will do this by default) and try again.

  • The project uses Windows functions on Cygwin and it's suffering from the problems described in the preceeding FAQ entry.

In all of this cases, please make sure to fix that upstream, or send your patches to the upstream maintainers, so the problems get fixed for the future.

6.6.

Why is __CYGWIN64__ not defined for 64 bit?

There is no __CYGWIN64__ because we would like to have a unified way to handle Cygwin code in portable projects. Using __CYGWIN32__ and __CYGWIN64__ only complicates the code for no good reason. Along the same lines you won't find predefined macros __linux32__ and __linux64__ on Linux.

If you really have to differ between 32 and 64 bit in some way, you have three choices.

  • If your code depends on the CPU architecture, use the predefined compiler definition for the architecture, like this:

    #ifdef __CYGWIN__
    # ifdef __x86_64__	/* Alternatively __x86_64, __amd64__, __amd64 */
        /* Code specific for AMD64 CPU */
    # elif __X86__
        /* Code specific for ix86 CPUs */
    # else
    #   error Unsupported Architecture
    # endif
    #endif
    
  • If your code depends on differences in the data model, you should consider to use the __LP64__ definition instead:

    #ifdef __CYGWIN__
    # ifdef __LP64__	/* Alternatively _LP64 */
        /* Code specific for 64 bit CPUs */
    # else
        /* Code specific for 32 bit CPUs */
    # endif
    #endif
    
  • If your code uses Windows functions, and some of the functionality is 64 bit Windows-specific, use _WIN64, which is defined on 64 bit Cygwin, as soon as you include windows.h. This should only be used in the most desperate of occasions, though, and only if it's really about a difference in Windows API functionality!

    #ifdef __CYGWIN__
    # ifdef _WIN64
        /* Code specific for 64 bit Windows */
    # else
        /* Code specific for 32 bit Windows */
    # endif
    #endif
    

6.7.

Where is glibc?

Cygwin does not provide glibc. It uses newlib instead, which provides much (but not all) of the same functionality. Porting glibc to Cygwin would be difficult.

6.8.

Where is Objective C?

Support for compiling Objective C is available in the gcc{4}-objc package; resulting binaries will depend on the libobjc2 package at runtime.

6.9.

Why does my make fail on Cygwin with an execvp error?

Beware of using non-portable shell features in your Makefiles (see tips at http://cygwin.com/faq/faq.html#faq.using.shell-scripts).

Errors of make: execvp: /bin/sh: Illegal Argument or make: execvp: /bin/sh: Argument list too long are often caused by the command-line being to long for the Windows execution model. To circumvent this, mount the path of the executable using the -X switch to enable cygexec for all executables in that folder; you will also need to exclude non-cygwin executables with the -x switch. Enabling cygexec causes cygwin executables to talk directly to one another, which increases the command-line limit. To enable cygexec for /bin and /usr/bin, you can add or change these entries in /etc/fstab:

C:/cygwin/bin /bin ntfs binary,cygexec 0 0
C:/cygwin/bin /usr/bin ntfs binary,cygexec 0 0

If you have added other non-Cygwin programs to a path you want to mount cygexec, you can find them with a script like this:

#!/bin/sh
cd /bin; for f in `find . -type f -name '*.exe'`; do
	cygcheck $f | (fgrep -qi cygwin1.dll || echo $f)
done

See http://cygwin.com/cygwin-ug-net/using.html#mount-table for more information on using mount.

6.10.

How can I use IPC, or why do I get a Bad system call error?

Try running cygserver. Read http://cygwin.com/cygwin-ug-net/using-cygserver.html. If you're trying to use PostgreSQL, also read /usr/share/doc/Cygwin/postgresql-*.README.

6.11.

Why the undefined reference to WinMain@16?

If you're using gcc, try adding an empty main() function to one of your sources. Or, perhaps you have -lm too early in the link command line. It should be at the end:

    bash$ gcc hello.c -lm
    bash$ ./a.exe
    Hello World!

works, but

    bash$  gcc -lm hello.c
    /c/TEMP/ccjLEGlU.o(.text+0x10):hello.c: multiple definition of `main'
    /usr/lib/libm.a(libcmain.o)(.text+0x0):libcmain.c: first defined here
    /usr/lib/libm.a(libcmain.o)(.text+0x6a):libcmain.c: undefined reference to `WinMain@16'
    collect2: ld returned 1 exit status

If you're using GCJ, you need to pass a "--main" flag:

gcj --main=Hello Hello.java

6.12.

How do I use Win32 API calls?

Cygwin tools require that you explicitly link the import libraries for whatever Win32 API functions that you are going to use, with the exception of kernel32, which is linked automatically (because the startup and/or built-in code uses it).

For example, to use graphics functions (GDI) you must link with gdi32 like this:

gcc -o foo.exe foo.o bar.o -lgdi32

or (compiling and linking in one step):

gcc -o foo.exe foo.c bar.c -lgdi32

The regular setup allows you to use the option -mwindows on the command line to include a set of the basic libraries (and also make your program a GUI program instead of a console program), including user32, gdi32 and comdlg32.

It is a good idea to put import libraries last on your link line, or at least after all the object files and static libraries that reference them.

Note

There are a few restrictions for calls to the Win32 API. For details, see the User's Guide section Restricted Win32 environment, as well as the User's Guide section Using the Win32 file API in Cygwin applications.

6.13.

How do I compile a Win32 executable that doesn't use Cygwin?

The compilers provided by the mingw-gcc, mingw64-i686-gcc, and mingw64-x86_64-gcc packages link against standard Microsoft DLLs instead of Cygwin. This is desirable for native Windows programs that don't need a UNIX emulation layer.

This is not to be confused with 'MinGW' (Minimalist GNU for Windows), which is a completely separate effort. That project's home page is http://www.mingw.org/index.shtml.

6.14.

Can I build a Cygwin program that does not require cygwin1.dll at runtime?

No. If your program uses the Cygwin API, then your executable cannot run without cygwin1.dll. In particular, it is not possible to statically link with a Cygwin library to obtain an independent, self-contained executable.

If this is an issue because you intend to distribute your Cygwin application, then you had better read and understand http://cygwin.com/licensing.html, which explains the licensing options. Unless you purchase a special commercial license from Red Hat, then your Cygwin application must be Open Source.

6.15.

Can I link with both MSVCRT*.DLL and cygwin1.dll?

No, you must use one or the other, they are mutually exclusive.

6.16.

How do I make the console window go away?

The default during compilation is to produce a console application. It you are writing a GUI program, you should either compile with -mwindows as explained above, or add the string "-Wl,--subsystem,windows" to the GCC command line.

6.17.

Why does make complain about a "missing separator"?

This problem usually occurs as a result of someone editing a Makefile with a text editor that replaces tab characters with spaces. Command lines must start with tabs. This is not specific to Cygwin.

6.18.

Why can't we redistribute Microsoft's Win32 headers?

Subsection 2.d.f of the `Microsoft Open Tools License agreement' looks like it says that one may not "permit further redistribution of the Redistributables to their end users". We take this to mean that we can give them to you, but you can't give them to anyone else, which is something that we can't agree to. Fortunately, we have our own Win32 headers which are pretty complete.

6.19.

How do I use cygwin1.dll with Visual Studio or MinGW?

Before you begin, note that Cygwin is licensed under the GNU GPL (as indeed are many other Cygwin-based libraries). That means that if your code links against the Cygwin dll (and if your program is calling functions from Cygwin, it must, as a matter of fact, be linked against it), you must apply the GPL to your source as well. Of course, this only matters if you plan to distribute your program in binary form. For more information, see http://gnu.org/licenses/gpl-faq.html. If that is not a problem, read on.

If you want to load the DLL dynamically, read winsup/cygwin/how-cygtls-works.txt and the sample code in winsup/testsuite/cygload to understand how this works. The short version is:

  1. Make sure you have 4K of scratch space at the bottom of your stack.

  2. Invoke cygwin_dll_init():

    HMODULE h = LoadLibrary("cygwin1.dll");
    void (*init)() = GetProcAddress(h, "cygwin_dll_init");
    init();
    

If you want to link statically from Visual Studio, to my knowledge none of the Cygwin developers have done this, but we have this report from the mailing list that it can be done this way:

  1. Use the impdef program to generate a .def file for the cygwin1.dll (if you build the cygwin dll from source, you will already have a def file)

    impdef cygwin1.dll > cygwin1.def
    
  2. Use the MS VS linker (lib) to generate an import library

    lib /def=cygwin1.def /out=cygwin1.lib
    
  3. Create a file "my_crt0.c" with the following contents

    #include <sys/cygwin.h>
    #include <stdlib.h>
    
    typedef int (*MainFunc) (int argc, char *argv[], char **env);
    
    void
      my_crt0 (MainFunc f)
      {
        cygwin_crt0(f);
      }
    
  4. Use gcc in a Cygwin prompt to build my_crt0.c into a DLL (e.g. my_crt0.dll). Follow steps 1 and 2 to generate .def and .lib files for the DLL.

  5. Download crt0.c from the cygwin website and include it in your sources. Modify it to call my_crt0() instead of cygwin_crt0().

  6. Build your object files using the MS VC compiler cl.

  7. Link your object files, cygwin1.lib, and my_crt0.lib (or whatever you called it) into the executable.

Note that if you are using any other Cygwin based libraries that you will probably need to build them as DLLs using gcc and then generate import libraries for the MS VC linker.

Thanks to Alastair Growcott (alastair dot growcott at bakbone dot co dot uk) for this tip.

6.20.

How do I link against a .lib file?

If your .lib file is a normal static or import library with C-callable entry points, you can list foo.lib as an object file for gcc/g++, just like any *.o file. Otherwise, here are some steps:

  1. Build a C file with a function table. Put all functions you intend to use in that table. This forces the linker to include all the object files from the .lib. Maybe there is an option to force LINK.EXE to include an object file.

  2. Build a dummy 'LibMain'.

  3. Build a .def with all the exports you need.

  4. Link with your .lib using link.exe.

or

  1. Extract all the object files from the .lib using LIB.EXE.

  2. Build a dummy C file referencing all the functions you need, either with a direct call or through an initialized function pointer.

  3. Build a dummy LibMain.

  4. Link all the objects with this file+LibMain.

  5. Write a .def.

  6. Link.

You can use these methods to use MSVC (and many other runtime libs) with Cygwin development tools.

Note that this is a lot of work (half a day or so), but much less than rewriting the runtime library in question from specs...

Thanks to Jacob Navia (root at jacob dot remcomp dot fr) for this explanation.

6.21.

How do I build Cygwin on my own?

First, you need to make sure you have the necessary build tools installed; you at least need gcc-g++, make, perl, cocom, gettext, gettext-devel, and zlib-devel. Building for 32-bit Cygwin also requires libiconv, mingw64-i686-gcc-g++, mingw64-i686-zlib, and mingw64-x86_64-gcc-core. Building for 64-bit Cygwin also requires libiconv-devel, mingw64-x86_64-gcc-g++, and mingw64-x86_64-zlib. If you want to run the tests, dejagnu is also required. Normally, building ignores any errors in building the documentation, which requires the dblatex, docbook-xml45, docbook-xsl, and xmlto packages. For more information on building the documentation, see the README included in the cygwin-doc package.

Next, get the Cygwin source. Ideally, you should check out what you need from CVS (http://cygwin.com/cvs.html). This is the preferred method for acquiring the sources. Otherwise, if you are trying to duplicate a cygwin release then you should download the corresponding source package (cygwin-x.y.z-n-src.tar.bz2).

You must build cygwin in a separate directory from the source, so create something like a build/ directory. Assuming you checked out the source in /oss/src/, and you also want to install to the temporary location install:

mkdir /oss/build
mkdir /oss/install 
cd build
(/oss/src/configure --prefix=/oss/install -v; make) >& make.out
make install > install.log 2>&1

If the build works, install everything except the dll (if you can). Then, close down all cygwin programs (including bash windows, inetd, etc.), save your old dll, and copy the new dll to the correct place. Then start up a bash window, or run a cygwin program from the Windows command prompt, and see what happens.

If you get the error "shared region is corrupted" it means that two different versions of cygwin1.dll are running on your machine at the same time. Remove all but one.

6.22.

I may have found a bug in Cygwin, how can I debug it (the symbols in gdb look funny)?

Debugging symbols are stripped from distibuted Cygwin binaries, so any symbols that you see in gdb are basically meaningless. It is also a good idea to use the latest code in case the bug has been fixed, so we recommend trying the latest snapshot from http://cygwin.com/snapshots/ or building the DLL from CVS.

To build a debugging version of the Cygwin DLL, you will need to follow the instructions at http://cygwin.com/faq/faq.html#faq.programming.building-cygwin. You can also contact the mailing list for pointers (a simple test case that demonstrates the bug is always welcome).

6.23.

How can I compile Cygwin for an unsupported platform (PowerPC, Alpha, ARM, Itanium)?

Unfortunately, this will be difficult. Exception handling and signals support semantics and args have been designed for x86 so you would need to write specific support for your platform. We don't know of any other incompatibilities. Please send us patches if you do this work!

6.24.

How can I adjust the heap/stack size of an application?

If you need to change the maximum amount of memory available to Cygwin, see http://cygwin.com/cygwin-ug-net/setup-maxmem.html. Otherwise, just pass heap/stack linker arguments to gcc. To create foo.exe with a heap size of 200MB and a stack size of 8MB, you would invoke gcc as:

gcc -Wl,--heap,200000000,--stack,8000000 -o foo foo.c

6.25.

How can I find out which DLLs are needed by an executable?

objdump -p provides this information, but is rather verbose.

cygcheck will do this much more concisely, and operates recursively, provided the command is in your path.

6.26.

How do I build a DLL?

There's documentation that explains the process in the Cygwin User's Guide here: http://cygwin.com/cygwin-ug-net/dll.html

6.27.

How can I set a breakpoint at MainCRTStartup?

(Please note: This section has not yet been updated for the latest net release.)

Set a breakpoint at *0x401000 in gdb and then run the program in question.

6.28.

How can I build a relocatable dll?

(Please note: This section has not yet been updated for the latest net release. However, there was a discussion on the cygwin mailing list once that addresses this issue. Read http://cygwin.com/ml/cygwin/2000-06/msg00688.html and related messages.)

You must execute the following sequence of five commands, in this order:

$(LD) -s --base-file BASEFILE --dll -o DLLNAME OBJS LIBS -e ENTRY

$(DLLTOOL) --as=$(AS) --dllname DLLNAME --def DEFFILE \
        --base-file BASEFILE --output-exp EXPFILE

$(LD) -s --base-file BASEFILE EXPFILE -dll -o DLLNAME OBJS LIBS -e ENTRY

$(DLLTOOL) --as=$(AS) --dllname DLLNAME --def DEFFILE \
	--base-file BASEFILE --output-exp EXPFILE

$(LD) EXPFILE --dll -o DLLNAME OBJS LIBS -e ENTRY

In this example, $(LD) is the linker, ld.

$(DLLTOOL) is dlltool.

$(AS) is the assembler, as.

DLLNAME is the name of the DLL you want to create, e.g., tcl80.dll.

OBJS is the list of object files you want to put into the DLL.

LIBS is the list of libraries you want to link the DLL against. For example, you may or may not want -lcygwin. You may want -lkernel32.

DEFFILE is the name of your definitions file. A simple DEFFILE would consist of ``EXPORTS'' followed by a list of all symbols which should be exported from the DLL. Each symbol should be on a line by itself. Other programs will only be able to access the listed symbols.

BASEFILE is a temporary file that is used during this five stage process, e.g., tcl.base.

EXPFILE is another temporary file, e.g., tcl.exp.

ENTRY is the name of the function which you want to use as the entry point. This function should be defined using the WINAPI attribute, and should take three arguments: int WINAPI startup (HINSTANCE, DWORD, LPVOID)

This means that the actual symbol name will have an appended @12, so if your entry point really is named startup, the string you should use for ENTRY in the above examples would be startup@12.

If your DLL calls any Cygwin API functions, the entry function will need to initialize the Cygwin impure pointer. You can do that by declaring a global variable _impure_ptr, and then initializing it in the entry function. Be careful not to export the global variable _impure_ptr from your DLL; that is, do not put it in DEFFILE.

/* This is a global variable.  */
struct _reent *_impure_ptr;
extern struct _reent *__imp_reent_data;

int entry (HINSTANT hinst, DWORD reason, LPVOID reserved)
{
  _impure_ptr = __imp_reent_data;
  /* Whatever else you want to do.  */
}

You may put an optional `--subsystem windows' on the $(LD) lines. Note that if you specify a --subsytem <x> flag to ld, the -e entry must come after the subsystem flag, since the subsystem flag sets a different default entry point.

You may put an optional `--image-base BASEADDR' on the $(LD) lines. This will set the default image base. Programs using this DLL will start up a bit faster if each DLL occupies a different portion of the address space. Each DLL starts at the image base, and continues for whatever size it occupies.

Now that you've built your DLL, you may want to build a library so that other programs can link against it. This is not required: you could always use the DLL via LoadLibrary. However, if you want to be able to link directly against the DLL, you need to create a library. Do that like this:

$(DLLTOOL) --as=$(AS) --dllname DLLNAME --def DEFFILE --output-lib LIBFILE

$(DLLTOOL), $(AS), DLLNAME, and DEFFILE are the same as above. Make sure you use the same DLLNAME and DEFFILE, or things won't work right.

LIBFILE is the name of the library you want to create, e.g., libtcl80.a. You can then link against that library using something like -ltcl80 in your linker command.

6.29.

How can I debug what's going on?

You can debug your application using gdb. Make sure you compile it with the -g flag! If your application calls functions in MS DLLs, gdb will complain about not being able to load debug information for them when you run your program. This is normal since these DLLs don't contain debugging information (and even if they did, that debug info would not be compatible with gdb).

6.30.

Can I use a system trace mechanism instead?

Yes. You can use the strace.exe utility to run other cygwin programs with various debug and trace messages enabled. For information on using strace, see the Cygwin User's Guide or the file winsup/utils/utils.sgml in the Cygwin sources.

6.31.

Why doesn't gdb handle signals?

Unfortunately, there is only minimal signal handling support in gdb currently. Signal handling only works with Windows-type signals. SIGINT may work, SIGFPE may work, SIGSEGV definitely does. You cannot 'stop', 'print' or 'nopass' signals like SIGUSR1 or SIGHUP to the process being debugged.

6.32.

The linker complains that it can't find something.

A common error is to put the library on the command line before the thing that needs things from it.

This is wrong gcc -lstdc++ hello.cc. This is right gcc hello.cc -lstdc++.

6.33.

Why do I get an error using struct stat64?

struct stat64 is not used in Cygwin, just use struct stat. It's 64 bit aware.

6.34.

Can you make DLLs that are linked against libc ?

Yes.

6.35.

Where is malloc.h?

It exists, but you should rather include stdlib.h instead of malloc.h. stdlib.h is POSIX standard for defining malloc and friends, malloc.h is definitely non-standard.

6.36.

Can I use my own malloc?

If you define a function called malloc in your own code, and link with the DLL, the DLL will call your malloc. Needless to say, you will run into serious problems if your malloc is buggy.

If you run any programs from the DOS command prompt, rather than from in bash, the DLL will try and expand the wildcards on the command line. This process uses malloc before your main line is started. If you have written your own malloc to need some initialization to occur after main is called, then this will surely break.

Moreover, there is an outstanding issue with _malloc_r in newlib. This re-entrant version of malloc will be called directly from within newlib, by-passing your custom version, and is probably incompatible with it. But it may not be possible to replace _malloc_r too, because cygwin1.dll does not export it and Cygwin does not expect your program to replace it. This is really a newlib issue, but we are open to suggestions on how to deal with it.

6.37.

Can I mix objects compiled with msvc++ and gcc?

Yes, but only if you are combining C object files. MSVC C++ uses a different mangling scheme than GNU C++, so you will have difficulties combining C++ objects.

6.38.

Can I use the gdb debugger to debug programs built by VC++?

No, not for full (high level source language) debugging. The Microsoft compilers generate a different type of debugging symbol information, which gdb does not understand.

However, the low-level (assembly-type) symbols generated by Microsoft compilers are coff, which gdb DOES understand. Therefore you should at least be able to see all of your global symbols; you just won't have any information about data types, line numbers, local variables etc.

6.39.

Shell scripts aren't running properly from my makefiles?

If your scripts are in the current directory, you must have . (dot) in your $PATH. (It is not normally there by default.) Better yet, add /bin/sh in front of each and every shell script invoked in your Makefiles.

6.40.

What preprocessor macros do I need to know about?

gcc for Cygwin defines __CYGWIN__ when building for a Cygwin environment.

Microsoft defines the preprocessor symbol _WIN32 in their Windows development environment.

In gcc for Cygwin, _WIN32 is only defined when you use the -mwin32 gcc command line options. This is because Cygwin is supposed to be a POSIX emulation environment in the first place and defining _WIN32 confuses some programs which think that they have to make special concessions for a Windows environment which Cygwin handles automatically.

Check out the predefined symbols in detail by running, for example

       $ gcc  -dM -E -xc /dev/null >gcc.txt
       $ gcc -mwin32 -dM -E -xc /dev/null >gcc-mwin32.txt

Then use the diff and grep utilities to check what the difference is.

6.41.

How should I port my Unix GUI to Windows?

Like other Unix-like platforms, the Cygwin distribtion includes many of the common GUI toolkits, including X11, X Athena widgets, Motif, Tk, GTK+, and Qt. Many programs which rely on these toolkits will work with little, if any, porting work if they are otherwise portable. However, there are a few things to look out for:

  1. Some packages written for both Windows and X11 incorrectly treat Cygwin as a Windows platform rather than a Unix variant. Mixing Cygwin's Unix APIs with Windows' GDI is best avoided; rather, remove these assumptions so that Cygwin is treated like other X11 platforms.

  2. GTK+ programs which use gtk_builder_connect_signals() or glade_xml_signal_autoconnect() need to be able to dlopen() themselves. In order for this to work, the program must be linked with the -Wl,--export-all-symbols linker flag. This can be added to LDFLAGS manually, or handled automatically with the -export-dynamic libtool flag (requires libtool 2.2.8) or by adding gmodule-export-2.0 to the pkg-config modules used to build the package.

  3. Programs which include their own loadable modules (plugins) often must have its modules linked against the symbols in the program. The most portable solution is for such programs to provide all its symbols (except for main()) in a shared library, against which the plugins can be linked. Otherwise, the symbols from the executable itself must be exported.

    If the package uses the CMake build system, this can be done by adding ENABLE_EXPORTS TRUE to the executable's set_target_properties command, then adding the executable's target name to the target_link_libraries command for the plugins.

    For other build systems, the following steps are required:

    1. The executable must be built before its plugins.

    2. Symbols must be exported from the executable with a -Wl,--export-all-symbols,--out-implib,libfoo.exe.a linker flag, where foo represents the name of the executable.

    3. The plugins must be linked with a -Wl,/path/to/libfoo.exe.a linker flag.

7. Copyright

7.1. What are the copyrights?

7.1.

What are the copyrights?

Please see http://cygwin.com/licensing.html for more information about Cygwin copyright and licensing.