Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Compiling

C++ Program Compilation


Video Summary: https://youtu.be/FgfDeW-2Ru0


Compile your C++ program on Replit

If you don't have hello.cpp from Lab 1, you can click on this link hello.cpp to get the code.

A common UNIX command to compile C++ program is g++.

Here is an example of compiling a program named hello.cpp, using

g++ -Wall hello.cpp -o hello

to compile and then using

./hello

to run the program. The -o lets your give a name to the runnable program. If you compile without -o like this:

g++ -Wall hello.cpp

then you get the default name a.out. You can run it by typing

./a.out

You will need to rebuild your program every time you make changes to it. Luckily, once you have written these commands once, you can press the up arrow while in the console to recall previous commands, so you only need to actually write it once.

Summary

g++ g++ is a common UNIX C++ compiler command. UNIX is case sensitive, so don't type a capital G by mistake.
-WallTurn on all warnings. Notice the capital W. Turns on warnings about subtle mistakes.
hello.cppYour C++ program name
-o hello The -o is used to create an executable file as specified by the name following -o. When you don't use -o, the executable filename will be called a.out.