Summary
In this chapter, we explored critical aspects of designing and developing shared libraries in C++. Shared libraries were initially conceived to promote code reuse, modularity, and efficient memory usage by allowing multiple programs to utilize the same library code simultaneously. This approach reduces redundancy and conserves system resources.
We delved into the nuances of developing shared libraries for different contexts. When the shared library is intended for use within a single project and compiled with the same compiler, shared objects (or DLLs) with C++ interfaces can be suitable, albeit with caution around singletons and global state to avoid multithreading issues and unpredictable initialization order.
However, for wider distribution where the end user’s compiler or programming language might differ, using C++ shared libraries directly is less advisable due to the instability of the C++ ABI across different compilers and versions. To overcome this, we...