graphitemaster/incbin logo

graphitemaster/incbin

Free

Include binary files in C/C++

FreeFree tier
Type
Open Source

About graphitemaster/incbin

graphitemaster/incbin is a header-only C/C++ library that embeds binary and textual files directly into executables at compile time. It provides macros (INCBIN and INCTXT) to include files as global symbols, with support for multiple compilers (GCC, Clang, MSVC, etc.), automatic alignment for SIMD, customizable symbol prefixes, and compatibility with MISRA C. This tool is ideal for embedding resources like images, fonts, and configuration files without external file I/O.

Key Features

Header-only library with no external dependencies
Supports GCC, Clang, MSVC, and many other compilers
Automatic alignment for SIMD instructions (SSE, AVX, Neon, etc.)
Customizable symbol prefix via INCBIN_PREFIX macro
INCBIN for binary data, INCTXT for text with null terminator
MISRA C compatible with independent verification
Produces global symbols for data, end, and size

Pros & Cons

Pros
  • Simple, single-header inclusion with no build-time tools
  • Works across a wide range of compilers and platforms
  • Efficient memory representation with proper alignment
  • Customizable naming to avoid symbol conflicts
  • Lightweight and easy to integrate into existing projects
Cons
  • Uses inline assembly, which may cause issues on uncommon architectures
  • Only supports compile-time embedding, not runtime dynamic loading
  • Large binary files may increase executable size significantly

Best For

Embedding images (PNG, JPEG) into games or applicationsIncluding font files or audio samples directly in executableBundling configuration files or shader code without external loadingEmbedding machine learning models or other binary assets

FAQ

What is the difference between INCBIN and INCTXT?
INCBIN includes binary files as an unsigned char array, while INCTXT includes textual files as a char array and adds a NUL-terminator byte, making it safe to use as a string.
Can I use incbin.h in C++?
Yes, but you should use extern 'C' when referencing the symbols from other translation units.
Which compilers are supported?
Supported compilers include GCC, Clang, Intel, MSVC, ARMCC, TinyCC, and many others as long as they support GCC inline assembler.
How can I change the symbol prefix?
Define INCBIN_PREFIX before including incbin.h. For example, #define INCBIN_PREFIX g_ will make symbols prefixed with 'g_'.