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