This is a minimal cross-platform C++ project that currently uses GLFW and OpenGL, built with CMake.
A Makefile is included to make building and running the project consistent across Linux, macOS, and Windows.
- CMake ≥ 3.16
- A C++17 (or newer) compiler
- GCC or Clang on Linux
- Clang (via Xcode tools) on macOS
- MSVC (Visual Studio) or MinGW on Windows
- Ninja (build tool)
git clone --recurse-submodules https://github.com/muntalee/sample-c-cpp-project
-
Ubuntu / Debian
sudo apt update sudo apt install build-essential cmake ninja-build libgl1-mesa-dev xorg-dev
-
Fedora
sudo dnf install gcc-c++ cmake ninja-build mesa-libGL-devel libX11-devel libXrandr-devel libXcursor-devel libXi-devel
-
macOS
brew install cmake ninja
(OpenGL and Clang come with macOS.)
-
Windows
-
Option 1: Visual Studio (MSVC toolchain)
-
Install Visual Studio Community (Choose Desktop development with C++ workload.)
-
Install Ninja or with Winget:
winget install Ninja-build.Ninja
-
-
Option 2: Scoop + MinGW (GCC toolchain)
-
Install Scoop (a Windows package manager).
-
Then all other dependencies
scoop install mingw scoop install ninja cmake
-
-
The Makefile comes bundled with preset commands you may use to compile your project.
make build # creates build
make compile # compiles the build
make run # build and run
make clean # cleans up build files / executable-
By default, the project builds an executable named
game. -
To change this:
- Update the variable
EXE = gamein theMakefile. - Change
gamein theproject(game VERSION 1.0)line inCMakeLists.txt.
- Update the variable
-
Place the library source under
extern/ -
In
CMakeLists.txt:add_subdirectory(extern/mylib) target_link_libraries(${OUT} PRIVATE mylib) target_include_directories(${OUT} PRIVATE extern/mylib/include)
If the library is hosted on GitHub or elsewhere, you can add it as a submodule:
git submodule add https://github.com/some/library.git extern/library
git submodule update --init --recursiveThen link it in CMakeLists.txt:
add_subdirectory(extern/library)
target_link_libraries(${OUT} PRIVATE library)When cloning this repo later, don’t forget to pull submodules too:
git clone --recurse-submodules https://github.com/your/repo.gitOr if you forgot:
git submodule update --init --recursive