from Hacker News

Collection of one-file C/C++ libraries with no dependencies, primarily for games

by elpocko on 2/8/25, 2:36 PM with 35 comments

  • by s5ma6n on 2/8/25, 3:50 PM

    Also relevant and useful single-file public domain libraries for C/C++

    https://github.com/nothings/stb

  • by HexDecOctBin on 2/8/25, 4:09 PM

    Here's a master list of most libraries like this: https://github.com/r-lyeh/single_file_libs
  • by amadio on 2/8/25, 10:25 PM

    I 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/755849fc2819d...

    I fixed this exact problem in a highly used library in high energy physics:

    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.

  • by test1235 on 2/8/25, 4:58 PM

    randy'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

  • by quotemstr on 2/8/25, 4:46 PM

    Amazing 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.

  • by malkia on 2/8/25, 5:04 PM

    These 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/2... - "Header only singletons are not working properly for Windows #2534"

  • by steeleduncan on 2/8/25, 4:10 PM

    > 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...

  • by Alifatisk on 2/8/25, 4:53 PM

    How 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?
  • by NullPrefix on 2/8/25, 3:52 PM

    Single 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