Hello from C/C++
To wrap up this tour, let’s also compile a small C/C++ program. When we get to Part 2 we will be switching language. While you are getting things setup, best to test this is working as well!
Creating a project
The C++ language aims to be very flexible, meaning you have to do lots yourself. As a result, there is no project concepts. All you need is a file with your code in it. We could put these all in one folder, or keep using a folder for each project.
Let’s create a code folder called CppCode in our Documents/Code folder. This can be used for any small C++ code files we want to work with.
Write the code
We can keep this simple. Add the following code for a simple command line program that outputs Hello World.
Compile and Run
When you are using C++ you will have to compile your code each time you change it. So you need to do two steps to run the code: compile then run.
Save your code and then try to compile and run it with the following:
The clang++
command runs the compiler. You pass it the file to compile, along with arguments to set the name of the program to create (-o hello
) and to link it with any libraries you use -l SplashKit
. We will explore this further in the later parts, but for now make sure this works, and you see the output message when it runs.
Once you have this running you should have everything ready to go!