stb: 19 single-file C libraries that trade features for integration ease
stb single-file public domain libraries for C/C++
At a glance
- What is it?
- The stb collection packs image decoding, font rasterization, audio, and utility code into single header files. Its public domain license and macro-based implementation model make it a common choice for C/C++ projects, but the project's own README warns about security bug handling.
- Who is it for?
- Adopt stb if you need a small, dependency-free C/C++ library for image loading, font rasterization, or similar tasks, and you can accept a public domain or MIT license with no attribution requirement. Skip it if your project has strict security response requirements, because the README explicitly states that security-relevant bugs are discussed in public and fixes may take significant time.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 1 day ago.
- What is it written in?
- Mainly C, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- nothings/stb35,037 ★ · +608
| Repository | 2026-08-18 | 2026-11-15 |
|---|---|---|
| nothings/stb | 34.4k | 35k |
608 Stars in the last 89 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What stb solves and who it is for
stb addresses a specific pain: pulling in a full image or font library often means adding a build system, multiple source files, and external dependencies. The stb collection packages 19 libraries as single header files, each with a documented API and no required build step. The intended user is a C or C++ developer who wants to drop one file into a project and get a working decoder, writer, or container. The README lists stb_image.h for loading JPG, PNG, TGA, BMP, PSD, GIF, HDR, and PIC, stb_truetype.h for parsing and rasterizing TrueType fonts, and stb_ds.h for typesafe dynamic arrays and hash tables. These are the most commonly used, but the collection also covers audio, math, parsing, and game development utilities. The project's own FAQ says the libraries are 'easier to integrate, easier to use, and easier to release' than existing open source libraries. That is the core value proposition: not raw performance or feature breadth, but simplicity of adoption.
The single-header implementation mechanism
Each stb header works in two modes. By default, including the header only declares functions. To get actual compiled code, you must define a library-specific macro in exactly one source file before including the header. For stb_image.h, the macro is STB_IMAGE_IMPLEMENTATION. The README gives this exact example: define STB_IMAGE_IMPLEMENTATION, then include stb_image.h in that one file. Other source files include the header normally, without the macro, to get declarations. This pattern means the library's implementation is compiled only once, avoiding duplicate symbol errors. The macro name is documented at the top of each library file. This design has a consequence: you cannot easily build multiple CPU-specific variants of a library in one translation unit. The README explains this with stb_image and SSE: it will use SSE2 only if you compile with -msse2, and it will not do runtime CPU detection. The README says the approved GCC approach for runtime detection requires multiple source files, which a single-header library cannot provide, so stb_image simply avoids runtime SIMD detection.
Getting stb running: commands and config
There are no build commands to run. You download the specific header file you need and place it in your project. For stb_image, the steps are: include the header in your normal code for declarations, then in one .c or .cpp file, write '#define STB_IMAGE_IMPLEMENTATION' before including it. The README stresses that this should be exactly one file, preferably one you do not edit frequently. That is the entire setup. The README also notes that each source file has an explicit dual license, public domain or MIT, so you can choose either. For GCC users, there is a specific compile-time consideration: to enable SSE2 in stb_image, you must compile with -msse2. Without that flag, the library uses no SIMD at all. This is a real constraint for performance-sensitive code, and the README points to GitHub issues #280 and #410 as examples of past problems with GCC and SSE workarounds.
License terms and re-licensing flexibility
The license is unusual in that it offers a dual choice. Every stb source file includes a public domain declaration and an MIT license. You can pick either. The README states, 'You can do anything you want with them. You have no legal obligation to do anything else, although I appreciate attribution.' That means you can wrap an stb library in a new library and release that new library under any license, including a proprietary one. The README explicitly confirms this: 'because it's public domain you can freely relicense it to whatever license your new library wants to be.' This is a significant advantage over copyleft libraries. However, the license field in the repository metadata shows NOASSERTION, which means GitHub's license detection did not classify it. That is a minor friction point for automated license compliance tools, but the README and each file's header make the terms clear. The MIT option exists specifically for organizations that are uncomfortable with public domain, as the README puts it, 'if you have lawyers who are unhappy with public domain.'
The security caveat you must read before adopting
The README opens with a warning in bold: security-relevant bugs are discussed in public in GitHub Issues and Pull Requests, and fixes may take significant time to be implemented or merged. It then says, 'If this poses an unreasonable risk to your project, do not use stb libraries.' That is a direct statement from the maintainer. It means security-relevant bugs are handled in public, with no guaranteed patch timeline. For a library that handles untrusted image files, like stb_image, this is a serious consideration. Image decoders parse attacker-controlled data by design, and vulnerabilities in such parsers are common. The public discussion of bugs means that when a vulnerability is disclosed, the details are visible to anyone, including attackers, before a fix may exist. This is not a hypothetical risk; it is a documented policy. If your project processes untrusted input and has a security response requirement, this alone could disqualify stb.
Performance and feature trade-offs compared to alternatives
The README is candid about how stb compares to other libraries. In the FAQ, when asked if stb libraries are better than existing open source libraries, the answer is that they are generally only better in integration ease. It states, 'They may be less featureful, slower, and/or use more memory.' That is a rare admission for a popular project. For example, stb_image can decode a set of formats, but it does not cover WebP or AVIF, which are common in modern web contexts. If you need those formats, you would look at libpng, libjpeg-turbo, or a format-specific decoder. stb_truetype is a rasterizer, but it does not handle OpenType shaping or complex text layout; for that you would need HarfBuzz and FreeType. The SSE limitation in stb_image means that on x86 without -msse2, you get scalar code, which can be significantly slower than optimized libraries that use runtime dispatch. The README also mentions that stb_image_resize2 is by Jeff Roberts and stb_dxt is by Fabian 'ryg' Giesen, indicating that not all code is by the primary maintainer. If you already use an equivalent library, the README says there is probably no good reason to switch.
Maintenance and upgrade cost
The repository has no GitHub releases, although the last push was on 2026-11-02. That means you cannot rely on a release cadence. The README shows version numbers for each library, like stb_image 2.30 and stb_truetype 1.26, but these are internal version strings, not GitHub releases. You track updates by watching the repository or checking the header files. Upgrade cost is low in terms of file replacement: you download the new header and swap it in. But the security caveat complicates upgrades. Because bugs are fixed in the public repository, you may need to pull from the default branch to get a fix, rather than waiting for a tagged release. The README does not describe any migration guides or compatibility notes between versions. For a collection with 38581 lines of C code across 19 libraries, that is a gap. You are essentially on your own to read the changelog, if one exists, or diff the header files. The project is not archived, so it is still maintained, but the maintenance model is informal and contributor-driven, which fits the single-file philosophy but may not suit teams that require formal release processes.
Editorial conclusion
Adopt stb if you need a small, dependency-free C/C++ library for image loading, font rasterization, or similar tasks, and you can accept a public domain or MIT license with no attribution requirement. Skip it if your project has strict security response requirements, because the README explicitly states that security-relevant bugs are discussed in public and fixes may take significant time. Before adopting any stb library, verify the exact version you plan to use, check the GitHub issues for known bugs, and confirm that the library's feature set and performance match your needs, since the README admits stb libraries may be less featureful, slower, or use more memory than alternatives.
Frequently asked questions
What are STB libraries?
Single-file public domain or MIT licensed libraries for C and C++, 19 of them in the README's table, covering image loading and writing, truetype font rasterization, Ogg Vorbis decoding, typesafe containers, and assorted graphics and game development helpers. Together they come to 38581 lines of C.
What is STB_Image?
stb_image is the image loading and decoding header, currently listed at version 2.30 and 7988 lines, reading JPG, PNG, TGA, BMP, PSD, GIF, HDR and PIC from a file or from memory. It is one of the five the project calls noteworthy, alongside the writer, the resizer, stb_truetype and stb_ds.
Can I relicense stb code inside my own library?
Yes. Because the code is public domain, you can freely relicense it to whatever license your new library wants to be, with no obligation to the original author. Every source file also carries an explicit dual-licence, public domain or MIT, for you to pick from.
Should I replace my existing image library with stb_image?
The project says there is probably no good reason to switch if you already use an equivalent library. The stated advantage is easier integration, easier use and easier release through a single file, and the stated cost is that these libraries may be less featureful, slower, or use more memory.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/nothings-stb)Star history chart for your README
[](https://hysenlabs.com/projects/nothings-stb)Was this useful?