Comment by erwincoumans
5 days ago
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.
We can also argue C++ is not a scripting language, which is what is approach is all about.
When C and C++ were the main programming languages during the 1990's, and commercial compilers abounded strangely we could manage handling all those build systems approaches.
1 reply →