3 ms·
I think people vastly undervalue static linking when it comes to compile times. If every file in a project changes every minute then yea - you're hooped... But
by munk-a 5y ago
I think people vastly undervalue static linking when it comes to compile times. If every file in a project changes every minute then yea - you're hooped... But usually certain groups will work in certain areas with those changes being synced only so often. If you examine the dependency tree and manage to split up the codebase into modules that you compile into .a files - then have a final step where you whip together any overly broad files along with just extracting the .o files from the archives[1] you'll live a happy life.
This can terribly fail if you have header files depended on by everything that constantly change - but honestly... that's a pretty bad code smell so either make an archive that's a dependency of all those others (and occasionally feel real pain when the header file actually gets updated) or else refactor things for sanity's sake.
A year and a half into my first job I was tasked with revising the build system and there are some really effective things you can do there without very much training. You want to lean on `make` a lot - no seriously, a lot - but if you do you can make some amazing things happen. You've also got a lot of cross platform tooling if you need to compile on different architectures - though scripting how those interact does get progressively more difficult in those cases.
1. Just in case you're unfamiliar - linux static libraries are essentially just an archive of a bunch of object files... so you can freely use ar to manipulate them in all sorts of ways https://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html https://tldp.org/HOWTO/Program-Library-HOWTO/static-librarie...
- rileymat2 5y agoI don't completely disagree, but templates become a big trap with respect to header files and trying to get static linked files precompiled.
- inetknght 5y agoIf you know your types then you can define the templates' bodies into a static library and keep the definitions there.
- boardwaalk 5y agoThe problems being: * External libraries don't do this. See: All those "header-only" libraries you see, starting back with boost * It's a total PITA once the types get complicated Source: Have worked for 10 years on a large codebase with "template auto instantiation" off.
- a_t48 5y agoEigen is the worst for this. :(
- munk-a 5y agoI agree a bunch with this. Templates can actually get really complicated quickly... In C++ if you want to generate the bytes to execute FooBar<string> then you actually need to reference FooBar<string> somewhere in the code to signal its necessary inclusion and later compilation steps can't build this for other types on the fly. If you have very generic and flexible templates defined in a static library the library needs to have actually forced the compilation for all the types you intend to use. So I do agree that templates remain a big pain!