Comment by ddtaylor
5 days ago
Thank you for sharing. The only thing I don't understand why this is a header only implementation with a macro that goes in a C++ file.
#define CANVAS_ITY_IMPLEMENTATION
5 days ago
Thank you for sharing. The only thing I don't understand why this is a header only implementation with a macro that goes in a C++ file.
#define CANVAS_ITY_IMPLEMENTATION
It is common for header-only libraries: you need to include this header in one c++ using the macro for linking (don't use that macro in other c++ files to avoid duplicate symbols). In C++, you can declare a function as many times as you want, but you can only define it (write the actual body) once in the entire project.
I understand that part, but I don't see why do this instead of basic Makefile or CMake setup. It seems like more work than a regular linker at that point. For what purpose?
Because not everyone is using Makefiles or CMake.
A true header-only library should be build-system agnostic and this is one way to do that.
We can argue about build systems for C++ all day long and never come to an agreement. With this approach this piece of code can be used anywhere.
2 replies →
that's a common pattern in C++ land because there is no standard way to use libraries in C++
https://github.com/p-ranav/awesome-hpp
It is a common pattern among those that don't want to learn build systems, which isn't exactly the same.
In my experience. I've run into the issue quite often. You find some library, it has its own build system (meaning not the one you're using). It has special rules etc... Integrating into your build system is time consuming and frustrating. Compiler errors from includes, linker errors, etc..
None of that happens with a single file C++ library.
2 replies →
Or among those who want to support any build system
1 reply →
Everything is easier with single file headers. This idea that a build system and single header libraries are mutually exclusive is silly.
You can take multiple single file libraries and put them into one compilation unit. Then you have minimal files and minimal compilation units. Compilation is faster, everything is simpler.
2 replies →
I wrote a mildly popular header only library with exactly this pattern once. Then there came a guy adding cmake. I didn't really know it back then so I didn't stop him. The downloads went to literally zero lol. Cmake is an extremely vocal minority.
1 reply →
And what build system do you recommend the entire ecosystem support? Well, I choose (arbitrarily different and incompatible one to prove a point). Do you see the problem?
1 reply →