5 ms·
Why, why do they make it header only? Is it so difficult to integrate a couple source file along with the existing headers? We should not forget compilation ti
by loup-vaillant 8y ago
Why, why do they make it header only? Is it so difficult to integrate a couple source file along with the existing headers?
We should not forget compilation times. A project I use depends on spdlog, a header-only C++ logging library. The thing adds almost two seconds per compilation unit to single threaded build times. And since logging is kinda used everywhere, the whole project takes forever to build (trice the build time it would have had without spdlog, I've measured).
What benefit is so great that it is worth killing compilation times?
- coss 8y agoEasy integration into projects and you can always make a precompiled header. Personally I love being able to test something out with ease and then make it work with the build system if I like the results.
- flohofwoe 8y agoProper "stb-style" header-only libs split the header into 2 parts: the declaration part that's always included and parsed but only contains the public API declarations, and the implementation part inside an #ifdef XXX_IMPLEMENTATION section which is only included and parsed in a single source file. The same idea can also be used for C++ headers (unless it's all template interfaces). With such stb-style headers, you can even get better compile times, because you can include all header-libs into a single implementation source file, giving the same advantages as unity-builds (merging all sources into one file). PS: origin of the name "stb-style": https://github.com/nothings/stb https://github.com/nothings/stb (although I guess the general idea existed before)
- bno1 8y agoI once tried to compile nheko, a Matrix client written in C++ and Qt. It makes heavy use of boost and compiling it crashed my system when I tried to compile using 2 jobs or more because it would eat up all my ram (6GB available at that time). Factor in the 2 seconds per compilation unit and it takes ages to compile. I managed to compile the native webrtc library with 8 jobs faster than this bare bones chat client on the same computer.
- ur-whale 8y agoDoesn't your compiler support pre-compiled headers?
- loup-vaillant 8y agoThe "rebuild from scratch" integration server does not.
- tjalfi 8y agoHere is why I used a header only library for my last C++ project. Earlier this year I wrote a Win32 program to solve an obscure issue for my employer. My main concern was making it possible for programmers with limited knowledge of C++ to maintain the application. We are a C# shop and I want my coworkers to be able to maintain the application after I leave. Here are some of the other things I did to make life easier for the maintenance programmer. I documented how the program works, what APIs it calls, and added links to Pluralsight courses on ATL and COM. The program uses printf format strings so there is a link to a tutorial on them. I added extensive logging with line numbers for every action that the program takes. You can reconstruct the control flow by looking at the log file. Yes, I tried doing this. I picked a header only logging library so that it would be easier for a maintenance programmer to update it. All they have to do is update the submodule that contains the library.