Use g++
command to compile a C++ program and build the executable so that you can run the C++ program on the Mac terminal. Below is the syntax of g++
command:
g++ Syntax
g++ programname.cpp -o executablename
Example
Suppose you have written a C++ program in a file named hellow.cpp
. Then open the terminal window change the directory to the file location and execute the following g++
command:
g++ hellow.cpp -o hellow ./hellow
The above first command will compile the hellow.cpp
and build the executable hellow
. The command in the second line above will run the C++ program hellow
.