10 ms·
Single-file C/C++ public-domain/open source libraries with minimal dependencies
- duneroadrunner 10y agoWell, since they seem to be including collections of elements, each with dependency on one or two files, SaferCPlusPlus[1] could be added to the "data structures" category. It's a collection of safe compatible substitutes for C/C++'s unsafe elements that's generally intended to be used as a whole, but certainly supports cherry picking of individual elements. For example, you could choose to use its safe substitutes for std::vector (and std::array) while foregoing its safe pointer substitutes. The implementation design was a trade-off between minimizing redundancy and minimizing dependencies (and inter-dependencies). Ultimately I decided minimal dependencies would be more appealing to the user. [1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus https://github.com/duneroadrunner/SaferCPlusPlus
- zielmicha 10y agoThere is also _GLIBCXX_DEBUG - if you have defined this symbol, glibc will use safer variant of std::vector, iterators etc, which asserts when you attempt to do bad things like reading out of range.
- duneroadrunner 10y agoYup. SaferCPlusPlus has vector and array substitutes that will also catch "use-after-free" bugs and use of invalid iterators. Clang/LLVM and gcc also provide "sanitizers" with much more comprehensive checking. But there are still situations when you'd want to use SaferCPlusPlus [1]. [1] https://github.com/duneroadrunner/SaferCPlusPlus#safercplusplus-versus-clangllvm-sanitizers https://github.com/duneroadrunner/SaferCPlusPlus#safercplusp...
- cobalt 10y agoThere's another set of similar libraries called the STB Libraries, primarily aimed at gamedev/graphicsdev: https://github.com/nothings/stb https://github.com/nothings/stb
- kLeeIsDead 10y agoThat's the exact same one as the first line in the OP, if you bothered to click the link
- cobalt 10y agoyes (firstly, clicking the link does not imply that you'd read the fucking intro so) they are by the same author, the link in the intro does not describe what they are for, and is easily missed
- deleted 10y ago[deleted]
- kLeeIsDead 10y agoJesus... I wouldn't want to have dinner with you.
- TD-Linux 10y agoThe OP one seems to be different - for example, it doesn't list stb_vorbis.c.
- TempleOS 10y agoAll will become clear when you knw it is God. You will die of shame for insulting His high priest.
- kevinoid 10y agoThis is a great list, it looks useful! In addition to clib[1] mentioned in this list, there's also CCAN[2]. It's another collection of small C libraries, but unlike clib and this list, the libraries are maintained as a single project (for better or worse). I'd love to see some more convergence on library search and package management for C. I was glad to see clib and CCAN consider coordinating.[3] Hopefully that effort will eventually bear fruit. 1. https://github.com/clibs/clib https://github.com/clibs/clib 2. https://ccodearchive.net/ https://ccodearchive.net/ 3. https://github.com/clibs/clib/issues/69 https://github.com/clibs/clib/issues/69
- stevemk14ebr 10y agoIMHO it's dumb to limit the libraries to just two files. Whether or not a library is included in the list should be determined on a per-library basis. Some header-only libraries simply require more than one header file or the source code becomes an absolute mess.
- CamperBob2 10y agoYou don't understand. It's OK if the source code becomes "an absolute mess." That's because it's a finite absolute mess, as opposed to most FOSS library and utility projects. An stb library is often the precise mess you need, and maybe even the one you deserve, with none of the seemingly-infinite, unbounded dependency messiness that you don't. Sean's doing the Lord's work here, or at least the Buddha's.
- ovao 10y agoMultiple parts to a header-only library can be concatenated into a single header file for easier inclusion, however. Some single header-only libraries are actually built this way. I agree with you in principle though. A directory of header files is, in practice, and in my experience, no more difficult to work with than a single header file and (can) allow for more modularity.
- IshKebab 10y agoThe single-file approach is to simplify including the library in your project. Just copy the file and type #include "whatever.h". It's because C/C++ still doesn't have a decent module system, nor a universally accepted library distribution system. You can still write the project as separate files and the concatenate them for distribution.
- aninteger 10y agoIt sorta does. It's just we use the packaging tools of the operating system (like apt-get and equivalent tools on other systems). That and pkg-config solves 99% of the problem on Unix-based systems. Windows on the other hand... Good luck.
- quinthar 10y agoIn the FAQ it just says "Come on" for SQLite included in the list. Can you provide a bit more detail? This feels like a pretty great option to include here.
- nickez 10y agoIt is a 6MB file produced from several source files.. Does any library count if I concatenate all the source files to a single file?
- quinthar 10y agoWell if the rules are: - 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 Then ya, I think it'd fit. I'm not sure why size matters here: the goal is to have libraries that are easily embedded. Anyway, I was mainly curious for the reason. If size is the reason, then that's that. Thanks!
- BinaryIdiot 10y agoSure, why not? It's just another distribution method of a library and it seems to fit the criteria. Why would it matter if the original developer coded everything in a single, huge file or multiple small ones that get distributed as one? Seems arbitrary.
- netheril96 10y agoI believe the "any library" should count if it just builds when concatenated. Many won't though.
- idm 10y agoMy theory: everybody knows sqlite can be distributed as a single-file library that you can happily embed. However, it's a pretty complex beast compared to the rest of the list and maybe it's outside the vision of the list altogether, which features much simpler projects. Edit: to be even clearer, sqlite is 100+ .c files. Yes, you can make it one "amalgamated" .c file, but no developer works on that file; they work on the 100+ smaller .c files.
- NotThe1Pct 10y agoI couldnt really find anything useful in there...
- israrkhan 10y agoThis is a great list, primarily for learning and experimenting. However I would not use these for production purpose. Typically production apps require Security, Performance, handling of edge cases, Memory leaks, and reliability in addition to functionality. It is easier to implement functionality in a single file library, however the scope increases significantly when you start adding things like os/hw/api abstraction layers, and aspects other than functionality.
- ovao 10y agoYou've not explained how a header-only approach precludes "security, performance, handling of edge cases, memory leaks [presumably you mean the absence of] and reliability".
- cgvgffyv 10y agoLeave him be, he must've just learned all those words, and in the great tradition of average human discourse, put them together to form a grammatically coherent yet nonsensical utterance that nonetheless achieves its main objective, namely making him feel good about himself. (See? I can do it too!)
- djsumdog 10y agoSo when you talk about security, you're usually talking about package management. The idea being, if you use official packages that are maintained, security advisories can be patched and you can get those with updates. At the same time, many of the major C++ applications we use don't use package management/external dependencies. Sometimes it's for security, but mostly it's for stability and reproducibility in bug management. Firefox has its own embedded PNG, JPEG et. al. libraries. Professor Silvio from Australia has done a lot of work on identifying outdated libraries with security vulnerability embedded in C/C++ projects.
- logicallee 10y agoFor anyone wondering why the FAQ says: >Q. Why isn't SQLite's amalgamated build on this list? >A. Come on. For the answer, look at the SQLite Amalgamation page[1] >1. Executive Summary >Over 100 separate source files are concatenated into a single large files of C-code named "sqlite3.c" and called "the amalgamation". The amalgamation contains everything an application needs to embed SQLite. The amalgamation file is more than 180,000 lines long and over 6 megabytes in size. So although it's technically a single file, at 180 000 lines and 6 Megabytes, it's not really in the spirit of the page. [1] https://www.sqlite.org/amalgamation.html https://www.sqlite.org/amalgamation.html
- liuyanghejerry 10y agoThis is so funny. BTW, even now, browser still love your JavaScript project in few large files. And before HTTP2 widely used, I think it's still the way to go.
- SwellJoe 10y agoI've lately found myself wondering why there isn't a C/C++ tool comparable to npm, cargo, cpanm, etc. There's more C/C++ code in the wild than most languages, but it's not easy to find, not easy to install, not easy to update (though that's a problem in the npm ecosystem, too), and not easy to integrate. A good package manager would go a long way toward modernizing the C ecosystem, I think.
- midita 10y agocoz c++ itself is architecture dependent. and even lots of c++ code are architecture dependent. c++ has much longer history than js or java. It runs on bare metal machine for all kind of purpose. So it is much harder to write universal useful libs.
- djsumdog 10y agoTotally. When you consider linking and binary compatibility, C/C++ does well with the Linux package management world that's grown up around it. Package management is somewhat less useful modern code that tends to self contain things (Java/Groovy/Scala) or where you want to pin dependencies for stability and create unique environments for them (Python's virtual env, Ruby's RVM, or .. and this is kinda a stretch, but Docker containers).
- coldtea 10y ago>coz c++ itself is architecture dependent. and even lots of c++ code are architecture dependent. For one, there are tons of universal useful libs for C/C++. Second, not all architectures matter equally. Beyond amd64 and ARM, few give a damn.
- zeta0134 10y agoI think that's because on most Linux-like systems, the distribution's built in package manager fills this role sufficiently. It's hardly perfect, but for many popular libraries you can just install the -dev package or equivalent, then include the headers from the system path and code away. I wouldn't mind a more dedicated tool though, especially because relying on distribution-specific packages tends to make cross platform support messy (see: heavy reliance on automake tools to correct for platform differences) and because most distributions only include the most popular, widely used libraries, and don't try to support newer or more niche tools.
- Xeoncross 10y agoI've been wondering where I can find guys to write a few dozen lines of C/C++ for my Go and/or bash scripts. I often need some simple thing that can take input from Stdin while I'm piping stuff around in a bash script. Like telling me the db audio level of a mp3 file while reading through all the files in a directory.
- Animats 10y agoGood idea, but submissions require forking the project, editing their directory file, and submitting a pull request. All this does is maintain a list. I just submitted "algebra3.h", vector functions for 2, 3, and 4 element vectors, all as inline C++. I've had that on a web site of mine since the 1990s.
- tripzilch 10y agoThat one seems to be in there now? Or at least in the recent additions section. It was the first one I clicked on :) I'm not very familiar with C++ (it's been a long time ago), but a friend recently came to me with some questions about vector/matrix algebra (though at first he didn't know his questions went by those names), wanted to write a toy physics engine in C++. I kind of assumed that C++ would have at least a basic selection of your typical vec2/3/4 data types and functions in its standard library--because C++ pretty much invented (or at least made popular, right?) operator overloading, and I don't know about everybody else, but vector math would be the very first thing that comes to mind learning about operator overloading and thinking "huh, what useful thing could I do with this". But it's not there (unless I didn't look properly?). So I told him (after explaining why vectors and matrices are nice to have in the first place) to write his own, because it's not hard if you don't need all the functionality in algebra3.h and it's a nice exercise for C++ classes and operator overloading. Now my questions, since we're in a thread with people that know a whole lot more about C++ than I do: Is there really no mathematical vector/matrix algebra data type with associated functions in the C++ standard libraries? (And I don't mean the one called Vector, that's really sorta-kinda like a list) If no, what do people generally use? Lightweight, or big framework? On the lightweight side of things, is algebra3.h a relatively good choice? I looked through the code and saw a few things that bugged me. Angles are in degrees (math code and functions use radians internally everywhere, this is just burning some useless muls and divs for a unit change that will be mistaken and cause a bug in someone's code some day somewhere). That one I'd immediately change before using this lib :) I'd like to reserve degrees just for displaying and input. I've been coding a lot of GLSL recently, and IMO their built-in vector math functions are pretty well thought-out, so there's some choices that differ. Like the overloaded asterisk (multiply) operator is sometimes a dot product, other times element-wise mul. From experience, I've found my code to be more readable when using an asterisk for operations just interchangeable with a scalar multiply (which is element-wise), 'dot' and 'cross' as names functions (you don't use the cross-product nearly as much to warrant its own operator, and the name 'dot' hits the sweet spot between being short enough so it doesn't matter you use it a bit more often) and preferably another operator for matrix-multiply (maybe the '@'? is that possible in C++?) to signify it's not commutative and just really really not at all what the asterisk-operator usually does with scalars and vectors (bonus, you also get an element-wise multiply for matrices, yay). Ooh and here's a nice one, is there any nice way to implement dimension swizzling of vectors in C++ like GLSL has? Like you could say P.xzyy and get a vec4 consisting of elements 0,2,1 and 1 of vector P, respectively. Because that was like the coolest thing ever when first learning GLSL, I've never seen anything like it :)
- greyman 10y agoI am glad that developers are willing to create truly free software under public-domain license, so one can just use it at will (for example copy just one method from the code) without worrying about licenses or needing to hire a lawyer.