SDL2_image and Libpng compatibility


#1

Hello,

To apply a patch to SDL_ttf, I tried to build SDL from sources. SDL2_image-2.0.5 seems not to work properly because of libpng compatibility. Compiling worked fine, but the program failed displaying this message during runtime:

libpng warning: Application built with libpng-1.2.54 but running with 1.6.34
Couldn't allocate memory for PNG file or incompatible PNG dll

I tried ./showimage heli.png and it failed too with the same kind of message:

libpng warning: Application built with libpng-1.2.54 but running with 1.6.34
INFO: Couldn't load heli.png: Couldn't allocate memory for PNG file or incompatible PNG dll

I’m using ubuntu 18.04, both libpng12-0 and libpng16-16 seem to be installed.
How could I build SDL2_image with libpng 1.6 or execute showimage with libpng 1.2 ?
Or maybe there is another way to solve this problem ?


#2

Ubuntu 18.04 does not ship libpng12. Maybe it failed to uninstall it during upgrade.
You can uninstall libpng12-0 and recompile SDL2_image.


#3

It’s hard to remove libpng12-0 because libsdl1.2 is installed and is used by many applications like VLC, and removing it will remove them. I tried it weeks ago and was very surprised to see all these applications disappeared, because I didn’t read well enough what was written by own screen ! :slight_smile:

Finally, I just removed libsdl1.2-dev that was here from years ago, ./configure and make the lib again and got the same result:

libpng warning: Application built with libpng-1.2.54 but running with 1.6.34
INFO: Couldn’t load heli1_1.png: Couldn’t allocate memory for PNG file or incompatible PNG dll

You’re perfectly right to advise me to do that: here the last line from compilation from the linker:

libtool: link: gcc -I/usr/include/libpng12 -g -O2 -D_REENTRANT -I/usr/local/include/SDL2 -o .libs/showimage showimage.o -Wl,-rpath -Wl,/usr/local/lib -Wl,–enable-new-dtags ./.libs/libSDL2_image.so -L/usr/local/lib /usr/local/lib/libSDL2.so -lm -ldl -lpthread -lrt

I think ./configure creates makefiles with the wrong png library when both libraries are installed. So I manually change libpng12 to libpng16 in the generated makefile. I was surprised to see one libpng16 (line 297) and many libpng12 in it.
make clean and make still gives the same error message.

But, this time, the linker command seems better:

libtool: link: gcc -I/usr/include/libpng16 -g -O2 -D_REENTRANT -I/usr/local/include/SDL2 -o .libs/showimage showimage.o -Wl,-rpath -Wl,/usr/local/lib -Wl,–enable-new-dtags ./.libs/libSDL2_image.so -L/usr/local/lib /usr/local/lib/libSDL2.so -lm -ldl -lpthread -lrt

Then I realized I don’t need the patch, and the SDL2_image from Ubuntu repository works perfectly.