5 ms·
Please don't make header file libraries. It will be messy and a nightmare to modify. Header files are for declarations and implementation should be in a separat
by n00b101 10y ago
Please don't make header file libraries. It will be messy and a nightmare to modify. Header files are for declarations and implementation should be in a separate file.
- boardwaalk 10y agoI agree. Unless it's out of necessity (C++ templates), all you're doing is killing my compilation time and I don't appreciate that. (And really, if it's that hard to add a source file to your project, your build system probably needs help.) The best way to be friendly to be developers who want to import your library, in my opinion, is to make it compile with all warnings enabled on common compilers.
- flohofwoe 10y agoI don't agree, header file libraries are great and the apparent advantage to header/source pair are negligible in practice (I use the STB headers all the time in different projects). One advantage is that you can simply add all the configuration defines (e.g. what assert macro and allocation functions to use, all the configuration options, ...) simply in front of the include statement and you don't need to mess around with the build system or compiler command line options to define those. Of course you usually wrap the header-only-lib in a central header/source pair of your own, so that those configuration defines and the implementation are in a single place instead of directly including the library header in different places.
- marssaxman 10y agoWhat's the advantage of packing everything into a header file if every single user of this "library" has to unpack it back out again? Why not just ship a header+source file, like civilized people have been doing since the dawn of C?
- dmytroi 10y agoI think "don't make header file libraries" is a good assumption to have, but reality is - stb libraries are one of the best library set I ever used in C/C++ domain. They are small enough to avoid "messy and a nightmare to modify" and powerful enough to be a great replacement for more "bloated" libs. For example I recently replaced libjpeg and libpng with one stb_image.h, it reduced 100kb of executable size, improved image loading speed by around 2x, reduced crashes on invalid image data for about 30% (we use american fuzzy lop fuzzer for testing).
- n00b101 10y ago> stb_image.h For the record, this library is a single file with 6,755 (!) lines of code [1] [1] https://github.com/nothings/stb/blob/master/stb_image.h https://github.com/nothings/stb/blob/master/stb_image.h