Compile: Sometimes when we compile, we want to give the output executable file a specific name. To do so, the compile command is slightly different. We still need to write
g++ and the file name in the terminal. After that, there should be
-o and then the name that you want to give to the executable file:
g++ hello.cpp -o hello
The compiler will then translate the C++ program hello.cpp and create a machine code file called hello.
Execute: To execute the new machine code file, all you need to do is type
./ and the machine code file name in the terminal:
The executable file will then be loaded to computer memory and the computer’s CPU will execute the program one instruction at a time.
Once again, we’re working with the Hello World program.
Click on the folder icon:
There should only be hello.cpp in there right now.
Compile hello.cpp using the terminal, but this time, give the executable file the name hello.
Click on the folder icon again. There should be a new hello file in the folder.