Follow the tutorial here - https://pranabdas.github.io/c-cpp/
Compile:
gcc filename.c
# linking math lib
gcc filename.c -lm
# show all compiler warnings
gcc -Wall filename.c
g++ filename.cpp
# specify certain standard
g++ -std=c++17 filename.cpp
This would produce executable with default name a.out
. You can specify the
executable name by using the -o
flag:
gcc filename.c -o program_name
For complex programs, you can use -g
(or -g3
) flag to embed debugging
information. -O
flag can be used to optimize the executable file (-O2
, -O3
denotes various levels of optimization).
Compiler (GCC/Clang) flags for warnings: -Wall
, -Wextra
, -Wpedantic
,
-Wunused
.
apt install cppcheck
cppcheck --enable=all filename.cpp
Cleanup (delete) all a.out
from the src
directory:
find /workspaces/c-cpp/src -type f -name a.out -delete