5 ms·
Collection of one-file C/C++ libraries with no dependencies, primarily for games
- s5ma6n 2y agoAlso relevant and useful single-file public domain libraries for C/C++ https://github.com/nothings/stb https://github.com/nothings/stb
- NullPrefix 2y agoSingle file or header only libraries were really useful before C++ had package managers. There's conan now. I think microsoft has some tools for that too - vcpkg or nuget
- Ygg2 2y agoNuget is .Net, no?
- shortrounddev2 2y agoThey have c++ packages too
- flohofwoe 2y agoI mean, even npm can be used as package manager for C/C++ libraries (e.g. https://gitlab.com/floooh/sokol-npm https://gitlab.com/floooh/sokol-npm), doesn't mean it's a good idea ;)
- mystified5016 2y agoI just spent the last week building up CI to distribute C++ packages on nuget. Microsoft really does not want you to do this, but they still allow it.
- atiedebee 2y agoThey are still general very easy to install. Also, C programmers don't seem to use any package managers other than the default system package manager and maybe git sub-modules (at least, not that I know of).
- shortrounddev2 2y agoYeah C programmers tend to be stuck in the late 90s
- NullPrefix 2y agoconan also works with C language, not just C++
- mananaysiempre 2y agoC on Unices is very well served by pkg-config[1] and its reimplementations[2,3]. (The last of these should also work well with MSYS2 on Windows, but it’s not—yet?—widely used in that environment.) The nice thing is that it has no opinions on your build system or even package manager, it’s purely for package discovery at build time. [1] https://www.freedesktop.org/wiki/Software/pkg-config/ https://www.freedesktop.org/wiki/Software/pkg-config/ [2] http://pkgconf.org/ http://pkgconf.org/ [3] https://nullprogram.com/blog/2023/01/18/ https://nullprogram.com/blog/2023/01/18/
- hgs3 2y ago> Also, C programmers don't seem to use any package managers other than the default system package manager and maybe git sub-modules (at least, not that I know of). For what it's worth, as someone who primarily writes C, not C++, I use the system package manager, vendoring, and sometimes Git submodules, depending on the project. On Windows, when I'm using MSYS2, I use the pacman package manager. If I'm targeting MSVC, I use CMake. For CMake, on Windows, I create my own directory where I place prebuilt dependencies for CMake to find [1]. With this approach, I can rely on CMake's builtin find_package behavior (no need for vcpkg and configure-time toolchain flags). [1] https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure https://cmake.org/cmake/help/latest/command/find_package.htm...
- flohofwoe 2y agoOne problem is that there's too many to choose from, so there might just as well be none from a library author's point of view. It's the same problem with putting build system files into your library source distribution - which build system to pick? Libraries that come as a header, or a small number of headers and source files have none of those problems because they are trivial to integrate without requiring package manager or build system magic. E.g. only top level projects should pick a specific build system and package manager, but not libraries.
- MaulingMonkey 2y ago+1 Just this month I saw yet another sufferer of the consequences of disparate build systems. This resulted in a mixture of GCC and LLVM, which disagreed on the basic ABI for C enums for unknown/none-platform ARM. (ARM's ABI gives multiple options, leaving the choice of which option to use to the platform ABI... which for unknown/none is obviously missing.) While I consider single-header libs overkill for my own taste in authoring things, I can't deny their continued ease of use in consumption. They're still useful. Sadly. If only because it won't be yet another source of debugging and fixing on my part when coworkers less familiar with integrating 3rd party dependencies into "our" build system either mess things up, or foist that work onto me - introducing delays and reducing bus factor.
- Joel_Mckay 2y agoIndeed, from a longterm maintenance perspective mitigating dependencies has advantages, and greatly simplifies porting. For example, the answer to "how do we build this on architecture X?"... should not be install 28000 source files, and wait 3 days to discover half of the packages broke the build... because fork you that's why. lol =3
- deleted 2y ago[deleted]
- taminka 2y agothere is no build system that everyone has installed/is familiar w, single header libraries are as portable as C or UTF-8 itself are (so still the best choice), the only other alternative i see it using C itself as build system (i mean why not)
- almostgotcaught 2y agoThere's a kind of hn comment that pops up very frequently - aspirational/delusional/out of touch: people repeating hype as truth that no one that actually lives in the space would repeat. Stuff like this (lol I don't know a single serious C++ project using conan/vcpkg/etc), or that mojo has replaced all of Python/C/C++ (not will replace but has!), or that Rust has replaced C/C++, or the LLMs have obviated everything. I have no clue how someone can both be so clueless and yet so sure.
- deleted 2y ago[deleted]
- sitkack 2y agoYou are just name calling, there is nothing substantive in your argument. It is rude and offputting.
- almostgotcaught 2y ago> You are just name calling who did i call a name?
- ranger_danger 2y agoThis is dogmatism, or "speaking in absolutes", and it's extremely common with pseudo-intellectuals in general. The Dunning-Kruger effect also applies to smart people. You don't stop when you are estimating your ability correctly. As you learn more, you gain more awareness of your ignorance and continue being conservative with your self estimates. My own take on this: I think real intelligence by definition requires humility. One has to realize that we can't know the things we don't know, which includes the fact that we can't always trust our own beliefs and opinions because we might be relying on faulty or incomplete information, or we might be suffering from a mental health problem, whether we are aware of it or not. "As a rule, strong feelings about issues do not emerge from deep understanding." -Sloman and Fernbach
- ranger_danger 2y agoI know this is only a sample size of 1 but I have never heard of any C or C++ developer using a package manager like conan/vcpkg/nuget, and I am assuming those are mostly used on Windows anyways.
- HexDecOctBin 2y agoHere's a master list of most libraries like this: https://github.com/r-lyeh/single_file_libs https://github.com/r-lyeh/single_file_libs
- steeleduncan 2y ago> Professional level 3D vector math I'm always suspicious of "Professional" in descriptions like this as it is a meaningless word you add to make it sound impressive. Also, in this case it means a 900 line math library with 78 lines of tests...
- samiv 2y agoself grandstanding is what it is.
- AlotOfReading 2y agoThe library is mostly a wrapper around intrinsics, so it's not doing much that would necessitate testing if the author is experienced enough. The fact that invert_safe() isn't actually safe isn't the greatest look here though.
- quotemstr 2y agoAmazing how the same people will go nuts for header-only C++ libraries, but the moment you involve an .a file, say "Noooo! you can't just vendor your dependencies! You need eight zillion apt dependencies!" Header-only libraries are static linking.
- ndriscoll 2y agoContainer images are also just a worse version of static linking (giving you all of the downsides and missing several upsides). Ideally the industry moves to something like nix for most purposes, and static linking is used for embedded systems and teaching.
- Alifatisk 2y agoHow does one aquire one of these one-file libraries and keep it updated? Is there an package manager for something like this? Can I use pacman?
- elpocko 2y agoThese libraries are not compiled, packaged or distributed on their own; you have to include their code directly as part of your C/C++ game or app. You acquire and update them using git.
- rickstanley 2y agoAnd if not using git, just fiddle around with a scripting language to automate the update, like check github's release API to see if there was some change between your local and the remote version somehow.
- ndriscoll 2y agoThese are meant to be vendored by your project, so git submodules are a natural way to do that.
- test1235 2y agorandy's also written the cute framework and is super helpful on discord, if you're into that sorta thing. I'm sure I've also spotted him in the SDL channels. https://github.com/RandyGaul/cute_framework https://github.com/RandyGaul/cute_framework
- malkia 2y agoThese do not seem to be pure "header-only", but involve #include-ing the same file at least once with "#define C2_xxx_IMPLEMENTATION 1" That's fine though. AFAIK, there is no sane way (across platforms) to have singletons, and that involves some of the the trick above, unless you know someother way If you do, please add your idea here - https://github.com/open-telemetry/opentelemetry-cpp/issues/2534 https://github.com/open-telemetry/opentelemetry-cpp/issues/2... - "Header only singletons are not working properly for Windows #2534"
- deleted 2y ago[deleted]
- amadio 2y agoI was just taking a look and couldn't help but notice the switch statement for your operator[], which likely causes a lot of unnecessary bad speculation at runtime: https://github.com/RandyGaul/cute_headers/blob/755849fc2819d4e61e7d999aa036d79706d832b0/cute_math.h#L99 https://github.com/RandyGaul/cute_headers/blob/755849fc2819d... I fixed this exact problem in a highly used library in high energy physics: https://gitlab.cern.ch/CLHEP/CLHEP/-/commit/5f20daf0cae911793d9aa5fc62987d6dc83647ab https://gitlab.cern.ch/CLHEP/CLHEP/-/commit/5f20daf0cae91179... Many believe the C++ compiler will magically optimize the switch away, but in some cases, like the example above for CLHEP, it doesn't happen, so you end up with bad performance.
- amadio 2y agoSince you left this "optimize me" comment here: https://github.com/RandyGaul/cute_headers/blob/755849fc2819d4e61e7d999aa036d79706d832b0/cute_math.h#L667 https://github.com/RandyGaul/cute_headers/blob/755849fc2819d... See an optimized quaternion multiplication implementation in SSE by me here: https://stackoverflow.com/questions/18542894/how-to-multiply-two-quaternions-with-minimal-instructions/18542951 https://stackoverflow.com/questions/18542894/how-to-multiply...