GCC not linking library with a "factory" mechanism
<p>I work on MSYS and I have a system of "factory", creating instances of classes according to external (specified) files. This system is provided by libA.
Using this mechanism, my test executable for a libB only "requires" the headers of B and the libA to compile, though it actually needs the library libB to run!
Knowing that, I do ask the compiler (through CMake) to link with the library libB using the flag -Wl,--no-as-needed:</p>

<pre><code> g++.exe -std=gnu++11 -O3 -Wl,--whole-archive CMakeFiles/test.dir/objects.a -Wl,--no-whole-archive  -o test.exe -Wl,--no-as-needed libB.dll.a libA.dll.a [other dependencies]
</code></pre>

<p>The executable does compile, but fails to run properly (the factory cannot build instance of objets provided by libB).
However, it is sufficient to add a dummy (real) instance of such object in the test.cpp (build without the mechanism of the factory) to ensure that libB is linked indeed, and then everything is fine. But that's dirty, and that's a "per case" solution. </p>

<p>So, besides this dirty fix, my first hint was for the "--as-needed"/"--no-as-needed" directive, but it does not fix my problem. I'm now open to any suggestion. Any help?</p>