Running and Compiling C/C++ code on Linux
C/C++ support is usually already there on Ubuntu
g++ --version
gcc --version
- If not, install
build-essential
build-essential
includesgcc
,g++
andmake
as well aslibc-dev
sudo apt install build-essential manpages-dev
The file extension is .cpp
on Linux or .C
Sample program
hello.cpp
#include <stdio.h>
int main() {
printf("bonjour le monde!");
return 0;
}
Compile code
g++ hello.cpp
By default it’ll generate a file called a.out
g++ hello.cpp -o output
output
will be the generated binary file
Run code
./output