Single-file public-domain/open source libraries with minimal dependencies
I am the author of a large number of single-file C/C++ public domain libraries.
I am not the only person who writes libraries like this, so below are other, similar libraries.
Generally, the following is a list of small, easy-to-integrate, portable libraries
which are usable from C and/or C++, and should be able to be compiled on both
32-bit and 64-bit platforms. However, I have not personally verified that any
specific lilbrary is as advertised, or is quality software.
Rules
Libraries must be usable from C or C++, ideally both
Libraries should be usable from more than one platform (ideally, all major desktops and/or all major mobile)
Libraries should compile and work on both 32-bit and 64-bit platforms
Libraries should use at most two files (one header, one source)
Exceptions will be allowed for good reasons.
Recent additions
Recent additions are marked with an asterisk in the left column.
Also you might be interested in other related, but different lists:
clib: list of (mostly) small single C functions (licenses not listed)
CCAN: package of lots of shareable C functions (mixed licenses)
Library listing
Public domain single-file libraries usable from C and C++ are in bold. Other
libraries are either non-public domain, or two files, or not usable from both C and C++, or
all three. Libraries of more than two files are mostly forbidden.
For the API column, "C" means C only, "C++" means C++ only, and "C/C++" means C/C++ usable
from either; some files may require building as C or C++ but still qualify as "C/C++" as
long as the header file uses extern "C" to make it work. (In some cases, a header-file-only
library may compile as both C or C++, but produce an implementation that can only be called from
one or the other, because of a lack of use of extern "C"; in this case the table still qualifies it
as C/C++, as this is not an obstacle to most users.)
Submissions of new libraries: I accept submissions (as issues or as pull requests). Please
note that every file that must be included in a user's project counts; a header and a source
file is 2 files, but a header file, source file, and LICENSE (if the license isn't in the
source file) is 3 files, and won't be accepted, because it's not 2 files. But actually
'LICENSE' is a problem for just dropping the library in a source tree anyway, since it's
not scoped to just the library, so library authors are encouraged to include the license in the
source file and not require a separate LICENSE.
Corrections: if information for a library above is wrong, please send a correction as an
issue, pull request, or email. Note that if the list indicates a library works from both
C/C++, but it doesn't, this could be an error in the list or it could be a bug in the
library. If you find a library doesn't work in 32-bit or 64-bit, the library should be
removed from this list, unless it's a bug in the library.
Why isn't library XXX which is made of 3 or more files on this list?
I draw the line arbitrarily at 2 files at most. (Note that some libraries that appear to
be two files require a separate LICENSE file, which made me leave them out). Some of these
libraries are still easy to drop into your project and build, so you might still be ok with them.
But since people come to stb for single-file public domain libraries, I feel that starts
to get too far from what we do here.
Why isn't library XXX which is at most two files and has minimal other dependencies on this list?
Probably because I don't know about it, feel free to submit a pull request, issue, email, or tweet it at
me (it can be your own library or somebody else's). But I might not include it for various
other reasons, including subtleties of what is 'minimal other dependencies' and subtleties
about what is 'lightweight'.
Why isn't SQLite's amalgamated build on this list?
There are technically several files here, not just one, however, the main file visit_struct.hpp can be used as a stand-alone and gets you the vast majority of the functionality. I think this is how most are using it. The extra headers are for extra features / compatibility with other libraries.
The main header is also quite short and the library as a whole is minimalistic, I think it fits well with the premise here.
I'd like to request an addition for TinySoundFont, a portable software synthesizer using SoundFont2 sound bank files.
It's a single-file library closely following the stb_howto.txt.
This is a series of MIT-licensed, one-file libraries for C++11 and C++14. They have been featured in CppCon for several years, and are in the process of becoming part of C++20.
what is it:
a variant of MS-IMA-ADPCM, with some stuff to fudge blocks to power-of-2 sizes, and some extended filters (intended to hopefully allow for higher audio quality vs raw ADPCM);
has a compatible subset with the normal MS-IMA-ADPCM (mono audio can be decoded, and encoder can be forced to produce normal ADPCM).
what is it intended for:
mostly for allowing arbitrary blocks to be decoded in arbitrary order, such as in the back-end of a mixer;
this avoids the cost (and memory use) of up-front decoding into PCM, while IME generally fast enough to not add a significant overhead over the use of raw PCM audio, with a bitrate not significantly worse than typical MP3 audio (given ~ 4 bits/sample, 22kHz gives 88kbps, and 11kHz gives 44kbps).
what does this not address:
it doesn't directly address either WAV loading, or managing a sample-block cache, as this would add a fair bit of code (and a simplistic WAV loader which spits out PCM would completely miss the point).
side notes:
elsewhere I also have a Windows ACM implementation (decodes this variant, but only encodes an older/simpler subset for now);
this is derived mostly from code copy/pasted from my 3D engine.
This library makes it simple to build otherwise non-trivial command line interfaces. It only requires you include the cmdline.h file. I've seen it used on Ubuntu, Fedora, OS X, and Windows. The license is somewhat ambiguous. The license reads like BSD.
Only implements DIT-2 (so, length in powers of 2) fft/ifft on complex numbers and only works with arrays of pairs of double precision floats. C-style C++ though.
I created a small library for writing command-line interfaces, kindda like the cmd module in Python.
It's located here: http://github.com/ronen25/libcmdf
It's single-header, ANSI C, Public Domain.
Wondering if it can be included here.
Thank you, and thanks for this incredible collection!
https://github.com/RandyGaul/tinysound - One file C/C++ API for loading/playing/looping sounds. Minimal dependencies. zlib license (in source as comment), 1 file.
inih is a simple .INI file parser for configuration files, perfect for embedded systems (I wrote a Nintendo 3DS Homebrew that used it). Would be a great addition to this list, for when you need something simpler than JSON for config files.
Category: images
License: CeCILL-C (close to the GNU LGPL) or CeCILL (compatible with the GNU GPL)
API: C++
Files: 1
Description: multi-format image processing and display
From my own collection of single-file libraries, I would like to submit selist.[hc], which implement a space-efficient list by way of an unrolled linked list, by bunching up several nodes into one, reducing both memory overhead for pointers and required number of allocations.
My repository is here: https://github.com/ennorehling/clibs and it contains more than those two files, but I don't feel the rest of the code is ready for submission (yet).
miniexpect is an expect-like library for C written as two files, a source file and a header file, so I believe it fits the definition. It has a single dependency (PCRE) but that is very widely available, even on Android. I have compiled this on many different Linux architectures, but to be fair never on Windows, although I don't have a reason to believe it would not work on Windows.
It's public domain, but I'm not sure if it matches all conventions. You need 2 or 3 files (depends whether you want to use the provided broken_main.cpp file, which just calls BrokenAPI:run()). It's C++ only as it relies on static initialization.
I just published https://github.com/DrMcCoy/dmc_unrar, a dependency single-file library to unpack and decompress RAR archives, usable from both C and C++. The license is GPLv2+, though, because the unrar code is based on existing GPLv2+ and LGPLv2+ code.
It can unpack RAR 1.5, 2.0/2.6 (including audio/media compression) and 2.9/3.6 (including PPMd, and all stock filters except the Itanium one). It can't do RAR 5 yet and it also doesn't support generic filter bytecode (which would run on a RARVM). There's several other smaller features still missing, but it is very much usable already.
The algorithm used in sdf.h does multiple passes and only produces an approximation. Since its invention, many exact linear time algorithms have been proposed, but people keep implementing the old algorithm.
I thought this might be a good opportunity to promote one of the newer algorithms.
A library creates a window with full-size webview and allows bi-directional communication between C/C++ and JavaScript inside the webview. The library was created in order to provide a simple way for creating modern nice-looking desktop GUI apps.
It can qualify as 2 files, one C/C++ header and a separate LICENSE file (MIT):
I have a public-domain AVL tree implementation in pure C89 that works well on embedded devices and in general applications as well. You can ignore the LICENSE file in the repository, as it's simply a public-domain placeholder. See src/avl.[ch] for the actual library code.
I have several other libraries that I will clean up and submit issues for as well, time permitting.
C++ mocking library (test support), single header file (in c++03 variant). Can runtime mock any interface or free library function on a variety of dev platforms (Mac, Linux, Windows supported). Already existed since 2008...