C++ Program Compilation

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

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 specifiled by the name following -o. When you don't use -o, the executable filename will be called a.out.


Copyright: Department of Computer Science, University of Regina.