gcc filename.c -o program_name
./program_name # Linux/macOS
program_name.exe # Windowsg++ filename.cpp -o program_name
./program_name # Linux/macOS
program_name.exe # WindowsIf you don't specify an output name with -o:
g++ script.cpp
./a.out # Linux/macOS
a.exe # WindowsCommon compiler flags:
-g- Enable debugging information-Wall- Enable most warning messages-Oor-O2- Enable optimizations-o <name>- Specify output filename-c- Output an object file (.o) instead of an executable-std=c++17- Specify C++ standard (other options: c++11, c++14, c++20)-std=c17- Specify C standard (other options: c11, c99)
g++ -o program -I/path/to/include program.cppg++ program.cpp -o program -L/path/to/libs -lname_of_libraryGeneric SDL2 linking pattern:
gcc -std=c17 main.c -I/path/to/SDL2/include -L/path/to/SDL2/lib -Wall -lmingw32 -lSDL2main -lSDL2 -o mainWindows example with placeholder paths:
gcc -std=c17 main.c -I/SDL2/include -L/SDL2/lib -Wall -lmingw32 -lSDL2main -lSDL2 -o mainFor Windows, you can combine compilation and execution:
gcc -o program program.cpp && program.exeFor Linux/macOS:
g++ -o program program.cpp && ./programg++ -o hello hello.cpp
./hellog++ -o hello hello.cpp
.\hello.exe