Duplicated Namespaces and Dynamically Linked Symbols
Let's learn about dynamically linked duplicated symbols and exporting names from libraries.
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:
Press + to interact
#include <iostream>void a() {std::cout << "A" << std::endl;}void duplicated() {std::cout << "duplicated A" << std::endl;}
The second implementation file is almost an exact copy of the first:
Press + to interact
#include <iostream>void b() {std::cout << "B" << std::endl;}void duplicated() {std::cout << "duplicated B" << std::endl;}
Now, let's use each function to see ...