Building Static Libraries
Resourceful Code Reuse — by Dmitry Zinoviev (15 / 20)
Published in
13 min readMar 23, 2022
👈 Compiling Object Files | TOC | Building Dynamic Libraries 👉
A well-debugged, well-tested, and well-documented object file with several functions and global variables is an excellent reusable code unit. You can link it with your program to get access to the previously implemented features. Yet, there are two practical considerations related to object files:
- You should collect the relevant files in an archive and give it a descriptive name.
- Some people consider it inelegant to have more than one public function per file. In fact, in Java, it’s explicitly forbidden to have more than one public class per file. If you try to avoid having more than one public class or function per file, you may end up compiling several object files that together implement the desired functionality. You’ll have to tell the linker to link all of them. The more files you have, the more you tell the linker until you forget why all those objects files are on the linker’s command line. This is also true of the file names that probably match the names of the public functions, but not the name of the problem they collectively solve.
- Linking a descriptively named archive, rather than individual object files, will take some pressure off you.
- You should store that archive someplace where the linker can find it without your assistance. Notifying the linker about the locations of…