Libpng/zlip conflicts with qt


#1

I have been trying to link both static juce and static Qt libraries into my application, and am seeing conflicts with the png_* symbols and z_* symbols, which are both included directly in the Qt and juce source. While Qt compiles the C source directly from it’s makefiles, I can’t see how the symbols could possibly collide because juce does a wonderful job of including the source directly (with extern “C”) from within the pnglibNamespace and zlibNamespace.

On mac everything will link if I comment out png_set_error_fn() and png_get_error_ptr() in pngerror.c, but then the app will crash with a backtrace that shows the qt sources using the functions in the juce code (probably conflicting over static vars or something).

Strangely, I solved the problem on mac by setting #define JUCE_INCLUDE_JPEGLIB_CODE 0 and adding the appropriate header search path to the Xcode project to use my own build of libpng, while also leaving Qt alone to link in it’s own libpng code. Why Qt’s libpng sources and my own libpng build didn’t conflict I have no clue, but everything works although the configuration is a pain for the rest of the team. I assume it would crash if we actually used the juce gui to load a png though.

On windows I haven’t found a solution yet. I get conflicting symbols from both zlib and libpng there (instead of just libpng symbols on mac).

Anyway, my point is that I have no idea why these symbols conflict if juce neatly wraps them in a namespace. None of this happens when compiling qt as a dll and juce as a static library. Maybe there’s some strange linker nuance with mixing extern “C” and namespaces? I used this LibDump tool to look at the symbols in the juce lib and it shows the png symbols defined right out of the namespace. hmmmmm

thanks!


#2

Weird and frustrating!

If the symbols are outside the namespace, then I guess it must be that using extern “C” cancels the namespace directive. The png stuff actually does compile ok without the extern “C” declaration - maybe try that and see if it works?