Skip to content

Instantly share code, notes, and snippets.

@ClearlyKyle
Last active September 1, 2025 08:20
Show Gist options
  • Save ClearlyKyle/9a81a8878991ed8020f5e7cc1ac1dd39 to your computer and use it in GitHub Desktop.
Save ClearlyKyle/9a81a8878991ed8020f5e7cc1ac1dd39 to your computer and use it in GitHub Desktop.
Building CIMGUI with MSVC cl.exe

Get cimgui files from: git clone --recursive https://github.com/cimgui/cimgui.git

Example project layout

project/
├── build/
├── cimgui/
│   ├── cimconfig.h
│   ├── cimgui.cpp
│   ├── cimgui.h
│   ├── cimgui_impl.cpp
│   ├── cimgui_impl.h
│   └── imgui/
│       ├── backends/
│       │   ├── imgui_impl_opengl3.cpp
│       │   ├── imgui_impl_opengl3.h
│       │   ├── imgui_impl_opengl3_loader.h
│       │   └── ...
│       ├── imconfig.h
│       ├── imgui.cpp
│       ├── imgui.h
│       ├── imgui_demo.cpp
│       ├── imgui_draw.cpp
│       ├── imgui_internal.h
│       ├── imgui_tables.cpp
│       ├── imgui_widgets.cpp
│       ├── imstb_rectpack.h
│       ├── imstb_textedit.h
│       └── imstb_truetype.h
│ 
├── example_sdl_opengl3.c
├── example_sdl_vulkan.c
├── ...
│
├── build.bat
└── build_cimgui.bat
@echo off
setlocal
set OUTPUT_DIRECTORY=build
set OUTPUT_FILE=%OUTPUT_DIRECTORY%\example
:: Set include paths
set CIMGUI_INCLUDE=/I cimgui
set IMGUI_INCLUDE=/I cimgui\imgui
set SDL2_INCLUDE=/I C:\VulkanSDK\1.3.280.0\Include\SDL2
set VULKAN_INCLUDE=/I C:\VulkanSDK\1.3.280.0\Include\
set INCLUDES=%IMGUI_INCLUDE% %CIMGUI_INCLUDE% %SDL2_INCLUDE% %VULKAN_INCLUDE%
:: Set dependancies based on the backend being used
set DEPS_LIB_FOLDER=/LIBPATH:C:\VulkanSDK\1.3.280.0\Lib ^
/LIBPATH:cimgui
set DEPS_LIBS=SDL2main.lib SDL2.lib Opengl32.lib vulkan-1.lib cimgui.lib
set LIBS=/link /SUBSYSTEM:CONSOLE %DEPS_LIB_FOLDER% %DEPS_LIBS%
set CFLAGS=/W4 /Zi
:: Set the example source to build
:: set SRC=example_sdl_vulkan.c
set SRC=example_sdl_opengl3.c
:: /Fo - object file destination
:: /Fd - rename program database file
:: /Fe - rename the exe file
cl /nologo %CFLAGS% /Fo%OUTPUT_DIRECTORY%\ /Fd%OUTPUT_FILE% /Fe%OUTPUT_FILE% %INCLUDES% %SRC% %LIBS%
@echo off
setlocal
set OUTPUT_DIRECTORY=cimgui
:: Set paths
set CIMGUI_PATH=cimgui
set IMGUI_PATH=cimgui/imgui
set IMGUI_BACKEND_PATH=cimgui/imgui/backends
:: Set include paths based on the backend being used
set SDL2_INCLUDE=/I C:\VulkanSDK\1.3.280.0\Include\SDL2
set VULKAN_INCLUDE=/I C:\VulkanSDK\1.3.280.0\Include\
set INCLUDES=%SDL2_INCLUDE% %VULKAN_INCLUDE%
:: Set which backends will be used
set DEFINES=/DCIMGUI_USE_VULKAN ^
/DCIMGUI_USE_SDL2 ^
/DIMGUI_IMPL_API="extern ""C"" __declspec(dllexport)" ^
/DIMGUI_USER_CONFIG="""../cimconfig.h""" ^
/DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
:: Compile imgui + backends
cl /nologo /c /Zi /Fo%OUTPUT_DIRECTORY%/ /I%IMGUI_PATH% %DEFINES% %INCLUDES% %IMGUI_PATH%\*.cpp %IMGUI_BACKEND_PATH%\*.cpp
:: Compile cimgui
cl /nologo /c /Zi /Fo%OUTPUT_DIRECTORY%/ /I%IMGUI_PATH% %DEFINES% %INCLUDES% /I%CIMGUI_PATH% /I%IMGUI_BACKEND_PATH% %CIMGUI_PATH%\*.cpp
:: Create cimgui library
lib /OUT:%OUTPUT_DIRECTORY%\cimgui.lib %OUTPUT_DIRECTORY%\*.obj
REM del %OUTPUT_DIRECTORY%\*.obj
echo Build completed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment