|Linux||whole operating system|
command-line and/or GUI
command-line and/or GUI
|Windoze||whole operating system|
command-line and/or GUI
Linux is a PC flavor of Unix. It is a 'free' OS and comes with a C++ compiler (g++). You can download it as either individual files or CD images (ISO images) which you can burn onto a CD-R (if you have access to a CD-R or CD-RW drive). You can also buy it at many stores (the bookstore on campus, WalMart, etc.).
In the past, I've recommended Mandrake for its security features and ease of use. [Un]Fortunately...Mandrake has merged with Conectiva. I've not experienced the new product, but it has good roots from which to grow. And there is still a download page (under Individuals|Products|...; you'll have to choose which of the desktop variants you prefer. Although I couldn't find any compilers except in the PowerPack variants...*shrug*).
Some might prefer RedHat for its stability, or even Slackware or Debian. Heck, there are thousands of 'em!
Using Linux requires that you either dual-boot your machine (set it up to boot either WinXX or Linux), set up a virtual machine, or dedicate a machine (must be a 386 or greater) to Linux. If any of this scares you or doesn't make sense, just try one of the DOS/WinXX compilering options below.
Further resources for Linux can be found at:
The C++ compiler on Linux, as I said, is g++. Here, though, is a script that emulates the CPP program you use here on campus. Simply save the file as "CPP" in your login directory. (You can save from your Web browser by holding down while right-clicking the link; one option will be to Save the Link.) Then go to a terminal prompt and execute:
$ su -c'cp ./CPP /usr/local/bin' $ su -c'chmod a+rx /usr/local/bin/CPP'
If you are on an Ubuntu-like system, you'll need to do sudo instead of su -c and you won't need the single quotes. On any system, it will most likely ask you for your password. But on different systems it will ask for the root/admin password or your own user password — pay attention to the prompt!
You'll need to have perl 5.6.0 (or higher) installed. To check on this, execute the following:
$ perl --version
As long as the version number is greater than or equal to 5.6.0, you're fine.
In addition, it will work best if you have the latest version of the GNU C++ compiler installed. To check this, execute the following:
$ g++ --version
As long as the version number is greater than or equal to 3.0.1, you're fine.
BTW, to execute your programs, you'll have to do so with:
The './' is the same standard security measure in Unix systems that you use here on campus.
Feel free to script your programs from Linux, if you like!
If you do, though, please follow the pwd command with this one:
$ CPP --version
That'll remind me that you are running on your own Linux box and not to expect your warning/error messages to be just like ours on mars. (Your compiler will be newer/better, after all...and this command will even tell me which version you have!)
You'll also have to make sure to install enscript and ps2pdf to make the standard script instructions work as they do on our campus *nix box.
Here are links to free C++ compilers/compiling environments for Windows. I've not used some of these. But, not only do I use both CygWin and Quincy regularly, but I've even heard recommendations for both of them from a respected programmers' journal (Dr. Dobbs Journal). That being said, any of them are still "use at your own risk":
command-line or GUI
CygWin is like having Linux as a desktop application under WinXX. Make sure that when you install you choose the GNU Compiler Collection (gcc and g++ are the most important parts). If you want to use CPP — like here in the lab, make sure Perl was selected for installation (it should be automatic, since much of the system requires perl scripts to run, but it can't hurt to make sure...).
Let me 'splain...no, there is too much...let me sum up:
If you want to have a nicer/friendlier environment for editing (like the nedit we have here in the lab, for instance), want to play with the graphics mentioned at the end of Chapter 2 (yes, the evil sections), or want to have a nice-like debugging environment, then you can proceed with the next list. Otherwise, just jump down to finish the install.
Once you've selected all the packages you'd like to have available (but don't worry! you can install more and/or update these at any time by simply running the "setup.exe" again), click "Next" and let it install for a while... (You'll also probably need to tell it to include lots of other things on which these main packages depend. There are more and more of these as time goes on. Each package tries to take on more responsibilities and needs more help doing it and...it's a vicious cycle.) It must download all the files, install them to your drive, and then run some 'post-install' chores.
Finally, decide if you want a desktop icon or a startup menu entry and you're ready to go!
The basic setup let's you click that desktop icon or go through the "Start|All Programs|Cygwin|Cygwin Bash Shell" menu location to get a terminal/command prompt. It should look somewhat like the one you have for your Unix account here (on mars) — ending with a nice "$ ", at least. *smile*
Now you can go on to learn how to edit your files within the Cygwin environment.
If you don't install X (all those files marked xorg...), then you'll just have vi or nano like in a Putty window here. (To use these, you'll have to have installed one of them. If you want nano's cousin pico, you'll have to install the email system "pine" — see how it says "It includes Pico" off to the right?)
If you did install X, then you can use gvim (a more graphically-oriented version of vi; in fact, you can actually go to vim.org to get gvim for WinXX if you like...*smile*) or Nedit. Both of these have nice features for programmers — like indenting multiple lines of code that you've just decided to put inside a loop or branch.
You can, though, always use Notepad to edit your program — make sure you put a .cpp or .C extension on it or Notepad always attaches a .txt. Your files for Cygwin are located in C:\cygwin\home\_____\.... The _____ is your WinXX login name and the ... is any subdirectories you've created for your programming projects (& labs).
To use the CPP script, you need to save that link as 'CPP' in your CygWin login directory (the one that opens when you open a CygWin window; probably c:\cygwin\home\???? with the ???? filled in with your Windoze account name). Open CygWin and type:
$ chmod a+x CPP
That will make it executable. Now all you'll have to do to compile your programs is:
$ ~/CPP hello
Assuming hello.C or hello.cpp is in the directory with you when you do that.
Or, to use the latest compiler (version 4), type this instead:
$ ~/CPP --compiler=g++4 hello
The '~/' on the CPP above is saying to run the command found in my (well, your, ...you get it, right?) login directory. That way you can run them even if you are storing your programs in subdirectories (i.e. subfolders).
Or, to not have to type that ~/ all the time, you could do this before you compile:
$ cp CPP /usr/local/bin
Now that you've compiled the program, you can execute it by typing:
That will run the program. (The './' tells CygWin to run the program that is in the current directory. Recall that this is a standard Unix security measure.)
If you want to run your scripts in CygWin, you may. Add the following steps to your CygWin setup (or any subsequent update).
Go to the "Utilities" group and make sure that "util-linux" is selected. (This allows you to run 'script' itself.)
Go to the "Text" group and make sure that "enscript" is selected. (This allows you to run 'enscript' for the PostScript transformation.)
Go to the "Graphics" group and make sure that "ghostscript" is selected. (This allows you to run 'ps2pdf' for the PS to PDF transformation.)
All the other commands we use to make a script are already installed by default with CygWin. *smile*
Once those are installed, feel free to script your programs from Cygwin, if you like!
If you do, though, please follow the pwd command with this one:
$ CPP --version
That'll remind me that you are running on your own Cygwin box and not to expect your warning/error messages to be just like ours on mars. (Your compiler will be newer/better, after all...and this command will even tell me which version you have!)
If anything doesn't work, just copy/paste your errors into a [plain text] email and I'll help you 'debug' it.
Copy/Paste for a Cygwin terminal window is in the Edit submenu of the Right-Click menu of the bar across the top of the terminal window — the title bar of the window. Or the Edit submenu found by Left-Clicking the Cygwin icon in the title bar. To copy, you have to Mark with the mouse what you want to copy. Then either go back to the Edit submenu and choose Copy or just hit Enter. Then, you can go to your email program and Paste there as you normally do. (BTW, to Paste in a Cygwin terminal window, you need to go through the Edit submenu and choose Paste. *shrug*)
If you are running X, however, and need to copy/paste from an xterm or rxvt, you can just use the mouse to Mark what you want copied — and it automatically is! (Kinda like in a Putty window...) Then, again, you can Paste in your email program as you normally do. (BTW, to Paste in an xterm or rxvt you can simply Middle-Click, Wheel-Click, or click both Left and Right buttons at once — depending on what type of mouse you have.)
MinGW is just a compiler. This is actually a port of the GNU Project's GCC's g++ compiler (for C++) to WinXX. It would be run from a DOS/CMD window. (Kinda like we run our compiler here at school in a terminal window.)
There is another VERY nice front-end (IDE) originally based on the MinGW backend (compiler). It was developed in a series of DDJ articles by Al Stevens. He made several versions since then (Quincy99, Quincy 2000, and Quincy 2002). All are available from Al's Quincy page (of all places!).
After Al left computing to return to his music career (*shrug*), some folks at CodeCutter took over the project.
This new version has seemed pretty stable when students used it in the past. And they've just recently released an update (Feb 2008). The new maintainers have dubbed it Quincy 2005 (although it's getting a little long in the tooth for that...*grin*).
To configure Quincy, make sure to do the following things (all are under Tools|Options):
In the Build tab, paste into the Compiler options line (near the bottom) part of the longest line from our CPP script. The part you want starts with -ansi and ends just before -fmessage-length=0. Oh, heck, here:
-ansi -Wall -W -Wfloat-equal -Winline -Wunreachable-code -Wredundant-decls -Wconversion -Wwrite-strings -Wcast-qual -Woverloaded-virtual -Weffc++ -fno-gnu-keywords -pedantic
Next go to the Editor tab and change the radio buttons to use Space characters instead of those evil tabs.
Finally, you can fix up the Editor settings otherwise as you'd like them to be: indent/tab size, colors for various parts of the language, etc.
You can also find resources for this IDE at:
command-line and GUI?
Watcom (who is an old and well-respected name in the compilers business) has apparently gone open-source! That means free compilers for us...yea!
GUI IDE for g++
Bloodshed Software also has several free compilers — including one for C++. (Don't let the name frighten you. *grin*) (Okay, so it's just a free IDE for the MinGW port of g++. It's still another option!)
My only beef with the Bloodshed folks is that they require you to add special code to a program to 'pause' the display of a console program at its end. Quincy pauses the console display automatically. It would be awesome if the Bloodshed folks would look through some old DDJ issues for the Quincy development articles or at the Quincy source (which is on the site or the Quincy CD) to see how that worked... (*nudge* *wink* Say-no-more...eh?) Of course, I'm sure they'd check with Mr. Stevens to make sure it was okay to borrow it first...*grin* (I think it is allowed in the license, actually, but it's been a while since I read it...*shrug*)
The command-line tool DJGPP works with the pseudo-GUI front-end RHide. (This is actually a DOS port of the g++ compiler, but will work in a DOS window. Note that RHide is also available for Linux — and Cygwin? — as an IDE for the real g++.)
There are many alternatives to these environments, most are based around the GNU g++ compiler or its MinGW variant (although there are other free compilers — avoid 'interpreters'!). Here is a site with a convenient list of IDEs and/or editors that are programmer-oriented. (Thanks TheFreeCountry!)