Here is an article explaining single header libraries: https://nicolashollmann.de/blog/single-header-libraries/ … The only thing I would comment on the article is that the point about single header libraries being slower to compile is not true in my experience :P
-
-
Replying to @SasLuca
Ah, that's mostly what I was expecting based on my limited C knowledge. I don't think they meant that a SHL is slower to compile than a normal lib, I think they meant that a SHL is slower to compile because you're compiling it *at all* instead of using a prebuilt artifact.
1 reply 0 retweets 0 likes -
Replying to @Lokathor
Linking is slower than compiling so I don't think even that is true :))
1 reply 0 retweets 1 like -
Replying to @SasLuca
Well, you have to link either way, right? You can't avoid doing a link. So for a "fresh build" of a downstream project, using pre-built artifacts is "zero build + some link" and inserting a SHL is "some build + some link".
1 reply 0 retweets 0 likes -
Replying to @Lokathor
No, with a SHL the library code is just included and compiled alongside your code. When you compile main.c you also compile lib.h with the implementation of the library.
1 reply 0 retweets 0 likes -
Replying to @SasLuca
Right, exactly, so a fresh build of the project, such as for CI, must build the SHL implementation code as well as your own code. Whereas if you had a pre-built artifact of the library then you'd skip the compilation of the library code and just build your own code. SHL+P >= 0+P
1 reply 0 retweets 0 likes -
Replying to @Lokathor
I guess it's my bad for assuming a single translation unit build which compiles instantly :))
1 reply 0 retweets 0 likes -
Replying to @SasLuca
Regardless of the rest of the organization of the project, if your lib is 10k lines, and your project is 5k lines, SHL is 15k lines compiled and pre-built is 5k lines compiled. Now, with single-translation-unit it might be too fast to notice either way, but it is a difference.
2 replies 0 retweets 0 likes -
This is an incorrect assumption. The compiler seeing all the at once means that no actual linking table is ever constructed, written, read, and resolved. It may often be _significantly_ faster to recompile an entire library than to link against a prebuilt version.
2 replies 1 retweet 4 likes -
Replying to @cmuratori @SasLuca
Ah, so when the final binary is known to be a single translation unit it short circuits the linking process, effectively?
1 reply 0 retweets 0 likes
So you just put "static" in front of all of your functions, and that prevents them from ever going into the linking table. This causes the compiler to treat them as intra-unit linkage and it doesn't ever have to even do the work of moving to the link phase.
-
-
So there is a potentially substantial savings (especially when you're in C++ name mangling ridiculousness land!) to be had here that you cannot discount out of hand.
1 reply 0 retweets 0 likes -
- Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.