How To Install and Use Cygwin
How To Install and Use Cygwin
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.
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. . .
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.)
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?. . .