Duplicated Namespaces and Dynamically Linked Symbols
Explore how duplicated symbols behave when using shared libraries in CMake, understand the influence of linking order on symbol resolution, and discover why using namespaces is essential to prevent naming collisions in complex C++ projects. Gain practical knowledge to manage linking challenges effectively.
We'll cover the following...
Dynamically linked duplicated symbols
The ODR rule works exactly the same for static libraries as it does for object files, but things aren't so clear when we build our code with SHARED libraries. A linker will allow duplicated symbols here. In the following example, we'll create two shared libraries, A and B, with one duplicated() function and two unique a() and b() functions:
The second implementation file is almost an exact copy of the first:
Now, let's use each function to see what happens (we'll declare them locally with extern for simplicity):