I have static library libA-static that defines function privateFunction and is linked into library libB-static. libB-static implements a lot of stuff but exports only one function publicFunction. libB-static is then linked into shared library  libC-shared that re-exports publicFunction. As suggested here and here, I compile all libraries with -fvisibility=hidden, label public with default visibility and link libB-static to libC-shared as whole archive.
My main program depends on libC-shared and libA-static. The setup works fine on Linux, Mac (and on Windows too), but on MinGW linking fails with multiple definitions of symbol privateFunction. The second definition comes from the import library libC-shared.dll.a. The size of import library is ridiculous for a single exported symbol (10MB) and it looks like it contains at least entire libB-static.
I tried linking libC-shared with -Wl,--exclude-libs,All, and the size of import library in this case is 1 KB, but publicFunction is then unresolved. I also tried linking libC-shared with -Wl,--exclude-libs,libB-static, but in this case linking of libC-shared fails to resolve privateFunction.
This is the linking command generated by CMake, where libC-shared=GraphicsEngineOpenGL-shared, libB-static=GraphicsEngineOpenGL-static and libA is all other static libs:
C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\G__~1.EXE    -shared -o GraphicsEngineOpenGL-shared.dll -Wl,--out-implib,libGraphicsEngineOpenGL-shared.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\GraphicsEngineOpenGL-shared.dir/objects.a -Wl,--no-whole-archive -Wl,--whole-archive libGraphicsEngineOpenGL-static.a -Wl,--no-whole-archive ../GLSLTools/libGLSLTools.a ../HLSL2GLSLConverterLib/libHLSL2GLSLConverterLib.a ../GraphicsEngine/libGraphicsEngine.a ../GraphicsAccessories/libGraphicsAccessories.a ../../Common/libCommon.a ../../Platforms/Win32/libWin32Platform.a ../../Platforms/Basic/libBasicPlatform.a -lShlwapi ../../Primitives/libPrimitives.a ../../External/glew/libglew-static.a -lopengl32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 
My main problem is obviously linking error, but ridiculous size of the import library is probably the key to the answer.