Lesson 2: Running the command prompt

The command prompt (or terminal on mac) is our gateway to talking to the computer. Instead of using a GUI program (one with buttons & graphics), the command prompt let's us talk to the computer just using text. It's the things you see in hacker movies with text scrolling across the screen, black & white or an eiry green. But rest assured we won't be needing to hack into the pentagon to make our games! We'll just be using a very simple command that will take our

We'll just be using a very simple command that will take our text files that have our code in & turn them into an executable* that the computer can run. The command line can do a lot of things (everything & more you can do with the GUI), such as create new folders, create files, connect to the internet.

Throughout your journey as a programmer, you'll pick up on some useful commands that make life easier for you. But you don't have to become a command line guru to become a great game programmer.

The command we'll be using is:

cl

gcc

So when we open up the command prompt on windows or on mac, terminal, will be greeted by some text & a blinking cursor. Now type the command from above & press enter. By pressing enter your saying to the command prompt - run this command. It will spew out some text, saying your useage isn't correct. This is because it expects to be passed a file to turn into a program. In our case it expects a file ending in .c or .cpp (for C code or C++ code respectively). So our job is to then create a file ending in .cpp (or .c) & run the command again, but this type followed by our file name.

When we actually compile our file we will want to type the soruce code file name as well.
Windows:

cl ourFile.cpp
Mac & Linux:
gcc ourFile.cpp

Instructions:

To open up the command prompt go to the search bar & type command prompt on Windows or Terminal on Mac.

Windows


Mac

Once open you'll be greeted by a window with a blinking cursor.

Windows

What the command prompt looks like on Windows.


Mac

What the Terminal looks like on Mac.

If you then type the command from above you'll get an error message.

Windows

On Windows you'll notice it doesn't recongise what cl means. This is because you need to do one extra step to get it working. This is a bit of an inconvienance, but you only have to do it once on opening the command prompt. From then on it will understand what cl means.
To get it working you have to run the vcvarsall.bat file. You don't have to understand what this is by any means, you just have to run it to get access to the compiler. It's located in a different place depending on what version of Visual Studio you have. On the 2017 version you just copy this in and press enter:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

If you're using a different version, the line you copy in will be slightly different. The best thing to do is google your year version of Visual Studio with vcvarsall.bat. Hopefully you'll find an answer, if not pop over to the discord channel & ask for some help.


On running the vcvarsall.bat file, you'll see this message.

Now when we run our cl command, we should see this message.


Mac

Typing the command gcc in.

After we press enter, we'll see this message.

This is saying it needs a file to convert to an executable*. This is the next step to getting a program up & running.

Phew! That was a big step, but well done. We now know what the command line is, and can run our compiler from it. Although this seems a lot at the moment, once we get into writing some programs, the process will become clearer & it will be a piece of cake. In the next project we will actually write some real C++ code, & then compile it using the steps we outlined above.

* - an executable is computer talk for a file that the computer is able to understand (i.e. machine code) & therefore execute what's inside it.

Quick Quiz:

What is the command line called on Windows & Mac? Click to see

Windows: Command Prompt Mac: Terminal

What is the command on Windows & Mac to run the compiler? Click to see

Windows: cl
Mac: gcc

On Windows, what extra step do you have to do to run the compiler from the command line? Click to see

You have to run the vcvarsall.bat file, which is located in different locations depending on your Visual Studio year version. For 2017 it is:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64

What extra bit of information do we have to tell the compiler, in order for it to actually make an executable? Click to see

The file name of the code you want to compile.

To Previous Lesson
To Next Project