SDL_Image IMG_Load fails on png with: "Failed loading libpng16-16.dll:"
Asked Answered
L

6

9

Whenever I try to load a PNG using SDL_Image's IMG_Load function it gives the error Failed loading libpng16-16.dll:. I have all the right dll's in the right path and I can use other parts of SDL_Image, but for some reason it can't load the libpng dll. How can I fix this? Any help is appreciated.

Lampoon answered 31/1, 2014 at 5:21 Comment(3)
What IDE are you using? Is it Visual Studio by any chance? If so, are you debugging directly from VS, or running the compiled executable directly?Belton
I am using visual studio and I am debugging within VS. would running it another way make a difference?Lampoon
Directly running the compiled executable makes no difference. Same result.Lampoon
B
6

See my article "SDL2: Loading Images with SDL_image":

If you're going to run from Visual Studio, make sure the image is in the same folder as your main.cpp file; otherwise if you're running straight from the executable, the image should be in the same folder with it.

Needless to say, what I wrote about the image here goes for the DLLs as well.

Belton answered 31/1, 2014 at 18:59 Comment(3)
I have placed the DLL along with the images in both the directory of the executable and the directory of the source. Still get the same error. Are there any additional libraries needed to use libpng?Lampoon
In the project for that blog post I have libjpeg-9.dll, libpng16-16.dll, libtiff-5.dll, libwebp-4.dll and zlib1.dll along with the obvious SDL2.dll and SDL2_image.dll. If you're only including libpng, I suggest you try including all the rest - there may be a dependency that you and I are not aware of. In fact I just checked, and libpng requires zlib: libpng.org/pub/png/libpng.htmlBelton
That was the issue. I copied libjpeg-9.dll, zlib1.dll, and libtiff-5.dll into the needed directories and now it works with no error. Thank you.Lampoon
I
25

It appears that libpng16-16.dll has a dependency on zlib1.dll for MinGW-w64 (32-bit). Try to include zlib into your dependnecies--include the DLL in the folder where the executable runs.

Indiscriminate answered 3/7, 2015 at 8:43 Comment(1)
I should also mention that zlib is one of the most popular libraries in the world and PNG uses the compression from zlib as a part of its format.Indiscriminate
B
6

See my article "SDL2: Loading Images with SDL_image":

If you're going to run from Visual Studio, make sure the image is in the same folder as your main.cpp file; otherwise if you're running straight from the executable, the image should be in the same folder with it.

Needless to say, what I wrote about the image here goes for the DLLs as well.

Belton answered 31/1, 2014 at 18:59 Comment(3)
I have placed the DLL along with the images in both the directory of the executable and the directory of the source. Still get the same error. Are there any additional libraries needed to use libpng?Lampoon
In the project for that blog post I have libjpeg-9.dll, libpng16-16.dll, libtiff-5.dll, libwebp-4.dll and zlib1.dll along with the obvious SDL2.dll and SDL2_image.dll. If you're only including libpng, I suggest you try including all the rest - there may be a dependency that you and I are not aware of. In fact I just checked, and libpng requires zlib: libpng.org/pub/png/libpng.htmlBelton
That was the issue. I copied libjpeg-9.dll, zlib1.dll, and libtiff-5.dll into the needed directories and now it works with no error. Thank you.Lampoon
K
1

The VS do not searches dlls on anywhere except the execution dir, so you probably need to copy that dll to the Debug/ directory on your solution's path.

Komatik answered 31/1, 2014 at 18:27 Comment(1)
I already have that along with the other necessary libraries in the Debug directory.Lampoon
L
1

Very niche answer, but for those running into this issue because of pySDL2, it could be caused because your python interpreter is sub-par. For me, using the windows store install for python interpreter 3.10, gave this issue. However, when I switched to 3.10 from python.org all my issues were fixed.

Lucic answered 16/3, 2022 at 22:5 Comment(0)
K
0

This link show you how to set up SDL library/libpng16-16.dll to be available for acceess by the compiler.exe (the last step right before the sample code)

yourProgram proprety page -> Builds event-> post-build event
in my case i have
copy “C:\Users\MehdiB\Desktop\C Program\Library\SDL2-devel-2.0.4-VC\SDL2-2.0.4\lib\x86\SDL2.dll” “$(OutDir)SDL2.dll”;
copy “C:\Users\MehdiB\Desktop\C Program\Library\SDL2_image-devel-2.0.1-VC\SDL2_image-2.0.1\lib\x86\SDL2_image.dll” “$(OutDir)SDL2_image.dll”;
copy “C:\Users\MehdiB\Desktop\C Program\Library\dll\libjpeg-9.dll” “$(OutDir)libjpeg-9.dll”

here where you can get this dll

Kenya answered 18/3, 2016 at 2:28 Comment(0)
R
-2

i just replaced zlib1.dll in system32 and SysWOW64 with the one downloaded from https://github.com/OctaForge/OF-Windows/blob/master/bin_win32/zlib1.dll .and worked nicely

Roselynroseman answered 9/7, 2018 at 20:42 Comment(1)
Replacing dll files in system32 and SysWOW64 is a very bad practice, you might break Windows! You'd better put this dll in the same directory as the binary, it's much safer.Eustatius

© 2022 - 2025 — McMap. All rights reserved.