0% found this document useful (0 votes)
69 views4 pages

How To Install and Use Cygwin

Cygwin allows users to run Linux/UNIX commands and applications on Windows. The document provides step-by-step instructions on how to install Cygwin, navigate the file system, edit and compile code using the xemacs text editor and G++ compiler, and run compiled programs. It emphasizes that learning to work in a command line environment is important for coding assignments and future work. The teaching assistant offers help for any issues that come up during the process.

Uploaded by

maxbyz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views4 pages

How To Install and Use Cygwin

Cygwin allows users to run Linux/UNIX commands and applications on Windows. The document provides step-by-step instructions on how to install Cygwin, navigate the file system, edit and compile code using the xemacs text editor and G++ compiler, and run compiled programs. It emphasizes that learning to work in a command line environment is important for coding assignments and future work. The teaching assistant offers help for any issues that come up during the process.

Uploaded by

maxbyz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

How to Install and Use Cygwin

August 28, 2006


Cygwin is a Linux-like environment for someone whos using Windows. Its important to learn how to use Cygwin to compile and run les because you will inevitably have to use Linux, UNIX, or SunOS in the future to do work, thus its best to get it out of the way now. Also, your coded homework assignments wont be compiled in Windows when we grade them, so its good to make sure that your code works ne and that youre comfortable in both environments. If at any point during these instructions you get confused or something bizzare happens, call over one of your TAs because were cracker-jack at xing problems you may have.

Downloading and Installing Cygwin


1. Your laptops came with Cygwin, but not the complete package, the rst step is to grab that o their site. So go to http://www.cygwin.com/ and click the Install or Update now! link (in the middle of the page, or the side, with the Cygwin icon above it) and download the setup le to somewhere where you can nd it. 2. Double click the setup le, click next, and then dot the Install From Internet box, then click next again (keep all the settings here the same), then click next one more time. 3. Make sure to set the local package directory to C:\cygwin, then click next, and then next again. Here pick a mirror, any mirror, and then click next again. 4. Theres a ton of info on this next page of packages to choose and such, just keep the Curr choice selected at the top. 5. In that big long list of packages click the plus sign next to Editors to expand that category. 6. Near the bottom of the list of editors under that expansion theres one called xemacs with the tagline A powerful highly customizable open source. . . . It should be the rst one listed right after the vim editor, and be 6,731k in size (I only list this because there are several avours of xemacs, and we want to grab the right one.) 1

7. Now that we know which editor were grabbing click the word Skip once in the New category as we dont want to skip xemacs, we want to install it. 8. Then go ahead and hit next and take a coee break. Your computer is going to download a plethora of packages, and then install them. . . (Also, it may tell you that you have to reboot after the install, if it does, do so) 9. Click nish and pat yourself on the back, youve nished a complete Cygwin install.

Navigating Around with Cygwin

Cygwin, linux, UNIX, etc. . . are all primarily command-line based. Thus, in a lot of ways its more of a pain to deal with (if youve used DOS before it is quite similar). However, you will discover later that command-line based operating systems are actually a whole lot more useful than Windows; that is when it comes to situations where you know what youre doing and want to get something done quickly and eciently. What follows is a step by step process for setting up a projects directory to do editing / programming in. 1. Run Cygwin. 2. This is the command-line interface, go ahead and type in cd C: and hit return. 3. Youre now in your root drive on your computer, were going to make a projects folder so type mkdir CS1Projects and hit return. 4. To see what you just did, you can list the contents of the directory by typing ls and hitting return. 5. Now type cd CS1Projects and hit return to enter your new CS1Projects folder. 6. For a lot more useful UNIX / Linux commands check out http://tinyurl.com/fg4mz 7. And now the real fun begins. . .

Editing Files in Cygwin

There are alot of dierent editors you can use under Linux / UNIX systems including Emacs, Pico, Nano, and Vi, here we will teach you how to edit using xEmacs because it is the most like Notepad in windows, but feel free to use any UNIX / Linux editor youre comfortable with. 1. While still in your CS1Projects folder type xemacs helloworld.cpp. 2. You are now in the Emacs text editor, you can move around and type just like in notepad. 3. Go ahead and type in the code from the Lab 1 handout under number 2 on the sheet. 4. Once youve copied the code in order to save and exit Emacs hit Ctrl+X followed by Ctrl+C, then type y to tell it to save the le and exit Emacs. (Yes were aware that xemacs has a nice GUI with which you have save, open, and other buttons and menus. However down the line, youll only be able to use regular emacs which has no buttons, so its best to learn to open les, edit, save, and exit this way.)

Compiling and Running Code in Cygwin

Unlike with windows, theres no candy-coated GUI to help you out, you must directly tell the Linux / UNIX environment to compile the code, and with what conditions. The advantage of this is that you have much more control and everything works faster than in Windows. 1. Do a quick ls to make sure your helloworld.cpp le is in your current directory before we re up G++. 2. G++ is the GNU compiler for UNIX / Linux systems, right now Im sure that means little to nothing but keep it in the back of your mind as it will be important later. Type in the following line at the prompt: g++ -o helloworld helloworld.cpp -Wall 3. Before you hit enter, lets pick through this seemingly jumbled command. . . The rst item, g++, tells Cygwin to use the G++ compiler The second item, -o helloworld, is a ag to let G++ know that you want to output the result of this compile to an executable le, a le called helloworld. If you do not set this parameter it will output by default to a.exe (on a true UNIX / Linux system this would be called a.out instead).

The third item, helloworld.cpp is the name of the le to be compiled. The fourth item, -Wall, is a ag to let G++ know that you want to know about any warnings that might exist in your code. Warnings wont stop compilation, but theyre a good indication of sloppy code. 4. If you got any compiler errors or warnings, read them and double check your code before compiling again. Make sure your code matches the code in the lab exactly, as one of the joys of coding is that if you misplace even one semicolon or bracket the code wont compile. If the problem persists call over a TA. 5. Now youve got your compiled executable le, if not then there were some compile errors and you should call one of those oh-so-kind TAs over to help you out. 6. So after all this work, lets run the thing. However, in UNIX / Linux environments we have to provide a path before running it so instead of typing just helloworld.exe and being happy we must include a dot-slash in there, so itll be ./helloworld.exe. Youre always going to have to do this when you try to execute something, if you really want to know why, ask one of the TAs at some point and theyll explain (this advice goes for about any esoteric question you may have throughout the course, its what were here for). 7. You should have seen Cygwin output a line of text proclaiming Hello world. Im alive!. If so, youre golden.

Congrats! Youve now installed Cygwin, written a program, compiled a program, and learned how to run executables! That wasnt so hard, was it?. . .

You might also like