Choose Your Own Adventure!

Make your choice from the following table:

I have a ___ machine
MacWindoze
I want toEmulate the Lab Setup Smooth transition: make your Mac feel just like the Lab setup we just learned! Smooth transition: make your Windoze box feel just like the Lab setup we just learned!
Have My Own Compiler It just feels better to have your own copy, doesn't it? It just feels better to have your own copy, doesn't it?

Emulating the Lab on a Mac

First you'll need a terminal. Luckily there is one already installed. It is buried in the Utilities folder under the Applications folder. It is called Terminal — shocking, isn't it?

Now that we have found the terminal program, run it. You'll note that it already feels just like the gnome-terminal we have back at school, doesn't it? *smile*

Next, we'll need to connect your machine to the Harper Unix machine. This is done with a Secure SHell connection: the SSH protocol. Again, this is already installed on your Mac! Just type:

$ ssh -Y login@ares.harpercollege.edu

at your Terminal prompt. Of course, make sure to replace login with your actual login ID for the gnome-terminal program. (Although ares might look funny at first, it is really the name of the Harper *nix server. Honest!)

The first time you connect, you'll need to validate the fingerprints of ares for ssh. After that, ssh will automatically validate ares' fingerprints for you. A copy of the fingerprints is located on this page.

If you are on a newer Mac, you may have to tell ssh to display the fingerprint in the simple format given on the other page. The simplest way to do this is with a special extra command-line argument when you next invoke ssh:

$ ssh -Y -o FingerprintHash=md5 login@ares.harpercollege.edu

This will make sure you can validate the fingerprint easily. But you don't have to do it all the time. You can revert to just the -Y and your login information thereafter.

Once you answer yes to the fingerprint confirmation (you have to type the whole word — not just a y) — and entered your password — you will see your local Mac Terminal prompt replaced with the standard Harper ares terminal prompt. That's because you've successfully connected to Harper and are connected to the exact same machine just like you do in the D258 lab here on campus! If you do an ls command you'll find the same files you have when you do ls here in the gnome-terminal in lab.

Next we'll load one of your programs — say the welcome program? — into nedit. Just type the following at your Terminal/ares prompt:

$ nedit welcome.cpp &

You should find that nedit pops up off to the side after a short interval. (Remember that the ampersand makes it release control of the terminal prompt so that you can still do more commands there even while nedit keeps running.) Now you can create/edit files on your Harper *nix account just like you can here in the lab!

If nedit doesn't appear — gives a Cannot open display error, make sure you have the -Y typed in on the ssh command as above (it has to be a capital Y!).

If that's not the problem, you may have to go download your X server. It was once provided with macOS. Then for a time it was available in the App Store. Then it was just linked from the App Store. Currently it is just linked from Apple's support pages. It is called XQuartz. The one caveat seems to be that you have to log out of your Mac and back in to have it complete its setup.

Once you can load nedit, you are almost all the way there! We just need a way to download your PDF'd scripts so you can email them to me. Unfortunately, WinSCP is not available for Mac — should I have said "spoiler alert!"? But there is a reasonable alternative: FileZilla. Go there and download and install the "All platforms" client. (Don't get the one straight from SourceForge! As it says, it has extra bundled content. *bleah* Hit the "Show additional download options" link and the first one is for Mac macOS. It isn't a normal DMG, but it works just fine. When you click the BZ2 file, it will unpack the app. If you want the app in a more normal location, just drag it to your Dock or Applications folder.)

When you run FileZilla it looks a lot like WinSCP but with 4 panes instead of 2. You can turn off the extra ones in the View menu. Just deselect "Local directory tree" and "Remote directory tree".

FileZilla may ask to be updated often. This is normal for a security conscious program like this. If you are also concerned about the security of your files, update. Otherwise, tell it you'll do it later. *shrug*

But how do you connect to Harper to download files? That's a little tricky the first time, but after that becomes easier. Your first connection, just fill in the "Host" input with ares.harpercollege.edu, the "Username" with your Harper *nix login (just like you did in front of the @ sign for the ssh command above), the "Password" with your gnome-terminal password (you can tell it whether to remember it or not soon), and the "Port" with 22 (as directed on the back of your lab handout or on the remote connection page), and click "Quickconnect". This first connection you'll also have to check the ares fingerprints as you did for ssh earlier. Remember, these are found on the remote connections page. Be sure to click the "Always trust..." checkbox before you click OK!

Later connections can be made from the little drop-down next to the "Quickconnect" button by selecting the sftp://login@ares.harpercollege.edu entry in the list — login being replaced with your Harper *nix login ID, of course.

Now you can drag-and-drop files from the ares side (right) to your machine's side (left). Unlike in WinSCP, you can even just double-click a file to copy it to the other side.

You now have a fully functioning replica of our lab setup on your Mac! You can be done right now if you like. *smile*

On the other hand, if you have a Winblows box to setup, too, continue reading. If you want to install your own compiler on your Mac — just for good measure? — see below. Otherwise, I really don't know how to help you here. Come see me and we can talk about it. *smile*

Emulating the Lab on Windoze

First you'll need a terminal. Perhaps the best is Putty. To find out more about downloading and configuring Putty, see the remote connections page.

Now that we have the terminal program, run it and connect to ares (Harper's *nix server). You should now see the standard Harper ares terminal prompt. That's because you've successfully connected to Harper and are connected to the exact same machine just like you do in the D258 lab here on campus! If you do an ls command you'll find the same files you have when you do ls here in the gnome-terminal in lab.

Before we can go on, though, we'll need another piece of support software. Go over to the Xming X Server site and grab the Windows installer.

Now install Xming with all the default settings except put a link to Xming itself on your Desktop. (If you want, you can go back to the Files area for the extra fonts also available. This gets rid of a couple of warning messages every time nedit launches.) Get it running and we should be good to go. (Note: Xming needs to be running every time you run Putty for nedit to launch properly. If you can't remember, just check the little triangle in the Taskbar at the bottom of the screen. There should be a black X with an orange swooshy circle around it.)

Next we'll load one of your programs — say the welcome program? — into nedit. Just type the following at your Putty/ares prompt:

$ nedit welcome.cpp &

You should find that nedit pops up off to the side after a short interval. (Unless you are truly unlucky and it pops up underneath the Putty window. *shrug*) (Remember that the ampersand makes it release control of the terminal prompt so that you can still do more commands there even while nedit keeps running.) Now you can create/edit files on your Harper *nix account just like you can here in the lab!

Once you can load nedit, you are almost all the way there! We just need a way to download your PDF'd scripts so you can email them to me. Just head over to get WinSCP. To find out more about downloading and configuring WinSCP, see the backing-up-your-programs page.

Now you can drag-and-drop files from the ares side (right) to your machine's side (left). Remember that you can't just double-click a file to copy it to the other side — that will just try to open the file for text-mode viewing!

You now have a fully functioning replica of our lab setup on your Windoze box! You can be done right now if you like. *smile*

On the other hand, if you want to install your own compiler on your Windoze machine, check here. If you'd rather install your own compiler on a Mac just keep reading. Otherwise, I really don't know how to help you here. Come see me and we can talk about it. *smile*

Having Your Own Compiler on a Mac

Downloading

There is only one compiler for the Mac: Xcode. If you are using the latest and greatest macOS, you can get it from the App Store — its icon is a hammer on a blueprint. But, if you are a little behind like me, you'll have to click through from the App Store entry to the Apple web site (the link is off to the right side). Navigate to "Develop" (at the top) and on that page "Downloads". Use your Apple ID to log in, click on "See more Downloads", and click each version of Xcode to find the one that matches your macOS version. (The only one labeled is 4.3.x is for Lion. *sigh* Worse, those from 6.2.x and above aren't labeled with an macOS version!) This may take awhile...

Running

Once you've downloaded and installed Xcode itself, you need to find it. If you don't see it in your Applications folder, it is quite well hidden. It made a new Developer folder on your Macintosh HD. Inside there you'll find a second Applications folder. And inside there you'll find Xcode itself. It's the one with the hammer on a blueprint.

Configuring

Now run Xcode and we can do a little configuration. First let's do the editor. Upon running Xcode, cancel any initial welcome screen nonsense and open the Preferences (Cmd-,). There you'll find the Text Editing 'tab'. The most important change here is to make sure lines are ending with the standard Unix LF. This setting is down near the bottom of the Editing 'column'. Next, near the top of this column, set the page guide at column 80. That way you know when your lines are getting too long to appear in the script PDF nicely and need to be wrapped.

Next we'll skip over to the Indention 'column'. Make sure the Tab key is NOT inserting actual tabs but spaces. (This is most recently called "Prefer indent using" for some reason.) Set both the "Tab width" and "Indent width" to 4 (or whatever value between 3 and 5 you like). And make sure line wrapping is off. (But didn't you just talk about having to wrap lines? Shouldn't I let the editor do it if I can? No. The editor sucks at wrapping lines of code. It generally does a poor job. I'm not a long-term Xcode user and am not exactly sure of its capabilities here, but I've seen almost no editors — programmers' editors included — that could wrap a line of code worth a damn!)

Other Preferences you may want to tweak are of course colors and fonts. Most of these are controlled under the Fonts & Colors 'tab', but there is also at least one other over in Debugging. (Most recently this tab was split up and the colors portion moved to a second Console 'column' under Fonts & Colors.)

Programming

Now we can start programming. For each program we can't just start editing a nice new file. We have to create a new Project and tweak the code template it opens for us a little. First, call for a New Project from under the File menu. Next choose for it to be a macOS build and that it is a "Command-line Tool" application. On the next screen make sure to give it a nice name reflective of what your program is intended to do! For some reason you also have to enter an organization identifier. Also make sure you select it to be using the C++ language! (These were once located in reverse. You would enter the application name first and choose C++ and then pick "Command-line Tool". Just letting you know in case you get an older version because of your macOS version.)

First, all Xcode project files are named main.cpp which is ridiculous! Do a rename click on that file there in the leftmost column and change it to be what you want.

But as you [true] click to the nice little C++ file Xcode created for you, you'll notice that it isn't using the same codes we are here in our low-level course. There are features beyond our current grasp that are used quite heavily — especially in a typical "Command-line Tool". And also the std:: syntax thing is, as mentioned in lecture, overzealous for us newbs. So let's clean it up a bit. You've got this:

#include <iostream>

int main (int argc, char * const argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

We want to, of course, add a using directive:

#include <iostream>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

Then we need to clean up the head of main:

#include <iostream>

using namespace std;

int main (int argc, char * const argv[]void) {
{
    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

And finally we can clean up that cout statement or even just replace it entirely — that's where our code for our new program needs to go after all. But we can make it into a nice start if we want:

#include <iostream>

using namespace std;

int main (void)
{
    // insert code here...
    std::cout << "Hello, World\n\t\tWelcome to the ___ Program!!!\n\n";
    // rest of new code replaces this comment...
    return 0;
}

Now we have a normal looking program:

#include <iostream>

using namespace std;

int main (void)
{
    cout << "\n\t\tWelcome to the ___ Program!!!\n\n";
    // rest of new code replaces this comment...
    return 0;
}

and can just work with that!

But how do we compile and execute? Well, my version of Xcode has this nice little Build and Run button at the top of the window. Newer versions have the Run choice inside the Project menu, I've noticed. But there is now also a cute little button that looks like the "Play" button on a media device (movies, music, etc.). Whatever way you do it, it should be fairly easy to ferret out. Just bring your laptop by if you need help!

Normal Workflow

In normal usage, then, you'll take your local compiler and develop a solution to some lab or project. (You can even use the same editing environment to create your info file and TPQ file. Right-click on the folder just above your C++ file and select "New file" and choose macOS Other and then "Empty". Change the name in the dialog slot "Save As" to the proper .info or .tpq file name — extension and all! — and hit Enter!) Now go to your file transfer program (FileZilla) and upload your file(s) to Harper's *nix server. Use your terminal to connect to the *nix server (ssh in a Terminal window). Run a script for your program and turn it into a PDF. Now back to the file transfer program (possibly hitting 'Refresh') to download the PDF file. Now over to your favorite email and send me the PDF with a proper subject!

You now have a fully functioning compiler on your Mac! You can be done right now if you like. *smile*

On the other hand, if you have a Winblows box you want a compiler on, too, continue reading. Otherwise, I really don't know how to help you here. Come see me and we can talk about it. *smile*

Having Your Own Compiler on Windoze

To tell you the truth, I've already covered free compilers for Windoze in quite a bit of detail on the free compilers pages. Which of those links you pick depends on what language you want to compile, now doesn't it?

Once you have one chosen, installed, and configured, you'll be able to create programs on your own machine even without an internet connection!

If you chose an actual Windoze-based solution (i.e. not installing a Linux [dual boot]), then you'll also need to get Putty and configure it as per the instructions on the remote connection page. Once that's done, install WinSCP and configure it as per the instructions on the backing-up-your-programs page.

If you chose to install Linux, make sure you've installed OpenSSH (the client should be all you need) and a nice file transfer program like FileZilla. Use the ssh command at your terminal prompt to connect to Harper's *nix server. (See above for how to type this command-line.) And use the instructions on the backing-up-your-programs page to configure your file transfer program.

In normal usage, then, you'll take your local compiler and develop a solution to some lab or project. (You can even use the same editing environment to create your info file and TPQ file.) Now go to your file transfer program (WinSCP or FileZilla probably) and upload your file(s) to Harper's *nix server. Use your terminal to connect to the *nix server (either Putty or ssh in a terminal window). Run a script for your program and turn it into a PDF. Now back to the file transfer program (possibly hitting 'Refresh') to download the PDF file. Now over to your favorite email and send me the PDF with a proper subject!