# How to Build Dear ImGui from Source: Complete Guide for All Platforms

> Learn how to build Dear ImGui from source with this complete cross-platform guide. Compile core files and backends for a smooth integration process.

- Repository: [omar/imgui](https://github.com/ocornut/imgui)
- Tags: how-to-guide
- Published: 2026-07-28

---

**To build Dear ImGui from source, compile the core library files ([`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp), [`imgui_draw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_draw.cpp), [`imgui_widgets.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_widgets.cpp), [`imgui_demo.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_demo.cpp)) together with your chosen platform and renderer backend files from the `backends/` directory, then link against the corresponding system libraries such as GLFW, SDL, or Win32.**

Dear ImGui is a pure-C++ immediate-mode GUI library maintained in the `ocornut/imgui` repository. Building it from source requires only compiling a handful of core source files alongside platform-specific backend implementations. This guide walks through the exact file structure, build commands, and integration steps needed to compile Dear ImGui on any supported platform.

## Understanding the Dear ImGui Source Structure

### Core Library Files

The core ImGui implementation is renderer-agnostic and resides in the repository root. These files implement the immediate-mode API, draw-list construction, window handling, and the demo UI.

- [`imgui.h`](https://github.com/ocornut/imgui/blob/main/imgui.h) – Public API declarations and configuration macros
- [`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp) – Core implementation including the main context and frame logic
- [`imgui_draw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_draw.cpp) – Low-level draw-list handling and rendering primitives
- [`imgui_widgets.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_widgets.cpp) – Standard widgets (buttons, sliders, input fields)
- [`imgui_demo.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_demo.cpp) – Comprehensive demo UI useful for testing builds

### Backend Files (Platform and Renderer)

Dear ImGui separates platform input handling from rendering through modular backends located in the `backends/` directory. You must select and compile one platform backend and one renderer backend.

**Platform backends** capture mouse, keyboard, and gamepad input while managing window creation:

- [`backends/imgui_impl_glfw.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_glfw.cpp) and [`imgui_impl_glfw.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_glfw.h) – GLFW windowing support
- [`backends/imgui_impl_sdl2.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_sdl2.cpp) and [`imgui_impl_sdl2.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_sdl2.h) – SDL2 support
- [`backends/imgui_impl_win32.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_win32.cpp) and [`imgui_impl_win32.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_win32.h) – Windows API support

**Renderer backends** consume `ImDrawData` and issue GPU commands:

- [`backends/imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_opengl3.cpp) and [`imgui_impl_opengl3.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_opengl3.h) – OpenGL 3.0+ support
- [`backends/imgui_impl_vulkan.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_vulkan.cpp) and [`imgui_impl_vulkan.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_vulkan.h) – Vulkan support
- [`backends/imgui_impl_dx12.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_dx12.cpp) and [`imgui_impl_dx12.h`](https://github.com/ocornut/imgui/blob/main/imgui_impl_dx12.h) – DirectX 12 support

## Build Instructions for Dear ImGui

### Clone the Repository

Begin by cloning the official repository to obtain the latest source code.

```bash
git clone https://github.com/ocornut/imgui.git
cd imgui

```

### Select Your Backend

Choose a platform backend and renderer backend combination based on your target system. The most common combination for cross-platform development is **GLFW** for windowing and **OpenGL 3** for rendering. Refer to [`docs/BACKENDS.md`](https://github.com/ocornut/imgui/blob/main/docs/BACKENDS.md) in the repository for the complete list of supported backends.

### Compile Using CMake (Cross-Platform)

The repository provides a [`CMakeLists.txt`](https://github.com/ocornut/imgui/blob/main/CMakeLists.txt) that automatically includes core files and backend sources. Create a build directory and run CMake with your backend selection.

```bash
mkdir build && cd build
cmake .. -DIMGUI_BACKEND=GLFW
cmake --build .

```

This generates a static library (`.a`, `.lib`) or shared library (`.so`, `.dll`) named `imgui` that includes both the core and selected backend code.

### Compile Using Make (Linux/macOS)

For a minimal build without CMake, navigate to one of the example directories that contains a Makefile. The `example_glfw_opengl3` directory demonstrates the standard build process.

```bash
cd examples/example_glfw_opengl3
make

```

This compiles the core ImGui sources, the GLFW and OpenGL3 backends, and the example application in a single step.

### Compile Using Visual Studio (Windows)

On Windows, open the provided Visual Studio project files located in the examples directories. For the GLFW/OpenGL3 example:

1. Open `examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj`
2. Select your target architecture (x64 or Win32)
3. Build the solution (Ctrl+Shift+B)

The project automatically links against the required GLFW and OpenGL libraries.

## Linking and Integration

After compiling Dear ImGui from source, link the resulting library to your application. You must also link against the system libraries required by your chosen backends.

For the GLFW + OpenGL 3 combination:

- Link `imgui` (the compiled library)
- Link `glfw` (windowing library)
- Link OpenGL system libraries (`opengl32.lib` on Windows, `-lGL` on Linux)

Include the headers in your source code:

```cpp
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"

```

## Complete Build Example (GLFW + OpenGL 3)

The following minimal application demonstrates the initialization sequence required after building Dear ImGui from source. This example mirrors the official [`examples/example_glfw_opengl3/main.cpp`](https://github.com/ocornut/imgui/blob/main/examples/example_glfw_opengl3/main.cpp).

```cpp
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>

int main()
{
    // Initialize GLFW and create window
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui Demo", nullptr, nullptr);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1); // Enable vsync

    // Initialize ImGui context
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO(); (void)io;

    // Initialize platform and renderer backends
    ImGui_ImplGlfw_InitForOpenGL(window, true);
    ImGui_ImplOpenGL3_Init("#version 330 core");

    // Main loop
    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
        
        // Start ImGui frame
        ImGui_ImplOpenGL3_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();

        // Render demo window
        ImGui::ShowDemoWindow();

        // Render ImGui
        ImGui::Render();
        int display_w, display_h;
        glfwGetFramebufferSize(window, &display_w, &display_h);
        glViewport(0, 0, display_w, display_h);
        glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
        
        glfwSwapBuffers(window);
    }

    // Cleanup
    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImGui::DestroyContext();
    glfwDestroyWindow(window);
    glfwTerminate();
    
    return 0;
}

```

Compile this example by linking against the Dear ImGui library built in the previous steps, along with GLFW and OpenGL libraries.

## Summary

- Dear ImGui requires compiling five core files ([`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp), [`imgui_draw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_draw.cpp), [`imgui_widgets.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_widgets.cpp), [`imgui_demo.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_demo.cpp), and [`imgui.h`](https://github.com/ocornut/imgui/blob/main/imgui.h)) alongside selected backend files from the `backends/` directory.
- The library uses a modular architecture separating platform input handling from rendering, allowing you to mix any platform backend (GLFW, SDL, Win32) with any renderer backend (OpenGL, Vulkan, DirectX).
- Build using CMake for cross-platform compatibility, Make for Linux/macOS examples, or Visual Studio project files for Windows development.
- Link the compiled static or shared library with your application along with the system libraries required by your chosen backends (e.g., `glfw`, `GL`).

## Frequently Asked Questions

### Does Dear ImGui require a specific build system?

No. Dear ImGui is designed to be build-system agnostic. You can integrate the source files directly into your existing CMake, Make, Visual Studio, Xcode, or custom build setup. The core library has no external dependencies beyond the C++ standard library, while backends depend only on their respective platform APIs (GLFW, SDL, DirectX, etc.).

### Which files must I compile to use Dear ImGui in my project?

You must compile the four core implementation files: [`imgui.cpp`](https://github.com/ocornut/imgui/blob/main/imgui.cpp), [`imgui_draw.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_draw.cpp), [`imgui_widgets.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_widgets.cpp), and [`imgui_demo.cpp`](https://github.com/ocornut/imgui/blob/main/imgui_demo.cpp) (optional but recommended for testing). Additionally, compile one platform backend file (e.g., [`backends/imgui_impl_glfw.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_glfw.cpp)) and one renderer backend file (e.g., [`backends/imgui_impl_opengl3.cpp`](https://github.com/ocornut/imgui/blob/main/backends/imgui_impl_opengl3.cpp)) matching your target environment.

### Can I build Dear ImGui as a shared library (DLL)?

Yes. While Dear ImGui is commonly used as a static library, you can compile it as a shared library by setting the appropriate compiler flags in your build system. When using Visual Studio, define `IMGUI_API` as `__declspec(dllexport)` during library compilation and `__declspec(dllimport)` when linking your application. The [`imgui.h`](https://github.com/ocornut/imgui/blob/main/imgui.h) header provides the `IMGUI_API` macro specifically for this purpose.

### Where can I find working build examples?

The `examples/` directory in the `ocornut/imgui` repository contains fully working projects for various backend combinations. The `example_glfw_opengl3` directory provides the most common reference implementation. Additionally, [`docs/EXAMPLES.md`](https://github.com/ocornut/imgui/blob/main/docs/EXAMPLES.md) lists all available example projects and [`docs/BACKENDS.md`](https://github.com/ocornut/imgui/blob/main/docs/BACKENDS.md) documents every supported platform and renderer backend.