SDL2_image fails loading libpng on latest versions when cross-compiling

I’m building an SDL application in Go using a sample repository to reproduce the problem. (full repro instructions here)

So I’m trying to build from Windows Subsystem for Linux to create a Windows build (using the bash script in the example). It works for SDL2_image version 2.0.1 but not newer versions. On newer versions, it fails with the following message:

Failed to load PNG: Failed loading libpng16-16.dll: The specified procedure could not be found.

I’m not sure how to debug from here, but the only thing I change to go from failure to working is changing the SDL2_image version. Any help would be appreciated!

1 Like

You’ll need to download that DLL, and place it in the same directory as your executable to get it to work. Are you running that from a Windows machine and getting that error, or when you’re compiling?

http://www.libpng.org/pub/png/libpng.html

The png library is being included, and lives in the same directory. This is an image from one of the links:

As you can see, libpng is in the folder.

And again, the only thing that changed was the SDL_image version to go from broken (on 2.0.2 and 2.0.3) to working (on 2.0.1).

And to clarify, this is a runtime error. Compilation succeeds without error.

Is that the 32-bit version of libpng or the 64-bit? Does it match which one you’re compiling with?

Also, where does that error occur? When the program attempts to load, or is it the error message that SDL_Image is returning?

I’m honestly not sure how to check what version of libpng it is, but it is the libpng bundled at https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.3-win32-x64.zip - I’m not building it myself or including it from somewhere else.

The fatal error occurs when attempting to load a png image using SDL2_image. The line printing the error message is here, immediately after a call to img.Load, which I believe corresponds to IMG_Load() declared in SDL_image.h.

If I’m not mistaken, that link is for the 64 bit version of libpng. Are you compiling for 32 or 64 bit?
libPNG 32bit might be what you need.

I am compiling for 64 bit, which seems to be the default for my machine. I’m making it explicit in my build file now to codify it (GOARCH=amd64).

I have discovered that the crash doesn’t happen if I build using version 2.0.3 and replace the libpng with the libpng provided in 2.0.1. Therefore I have decided to submit a bug.

Sorry I couldn’t have been better help.

I love you dude! The issue continue to v2.0.5… Thanks a lot