Is there a way to uniquely identify a static library at runtime in C++?
<p>With dynamic/shared libraries we can retrieve the DLL/so/dylib handle containing a function address at runtime (with GetModuleHandleEx or dladdr). This could be used to associate some code with the dynamic library which contains it. 
The problem comes With static libraries because every link operation is deferred until the final executable link operation and every function gets its resolved final pointer at this time. We can't then associate any address or function pointer to the static lib. </p>

<p>Multiple inline function pointers get an unique pointer at link time (duplicates will be thrown away). So we cannot use one of them to identify the static library.</p>

<p>Multiple static will get a pointer for each translation unit, which is also not identifying the static library.</p>

<p>My only solution for now is to provide an UUID with -DUUID= different for each static library used in the project, but that would be cool to automatise this with an internal compile time feature/trick. </p>

<p>My question is : is there a trick to uniquely identify a static library at runtime on windows and unix platforms (linux/OSX/iOS/Android...) ?
(not tested yet, but for windows, the "__ImageBase" symbol trick could do the job even if i don't like it, but for other platforms i'm stuck).</p>

<p>To be more precise of what i try to achieve, i'm looking to map at runtime some global variable with the respective static library they belong too. </p>

<p>For example: in lib0.lib built from this lib0.cpp code: </p>

<pre><code>namespace {
 AClass global0;
}
</code></pre>

<p>and in lib1.lib built from this lib1.cpp code: </p>

<pre><code>namespace {
 AClass global1;
}
</code></pre>

<p>I want to be able at runtime to map in a generic way :
- &amp;global0 with "lib0.lib" 
- &amp;global1 with "lib1.lib"</p>

<p>Hope my question is a bit more clear... </p>