g++ is the GNU C++ compiler invocation command used for preprocessing, compilation, assembly, and linking of source code to generate an executable file.
g++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Install if needed
sudo apt install g++
Compile a Single C++ File
Create a main.cpp file
main.cpp
#include <iostream>int main(){ std::cout << "Compile me if you can" << std::endl; return 0;}
Compile the program
g++ main.cpp -o test_program
Run the program
./test_program
Output
Compile me if you can
Useful Compiler Flags
-Wall β enable common compiler warnings
-O2 β optimization level 2
-std=c++17 / -std=c++20 / -std=c++23 β specify language standard