SDL_Image IMG_Load fails on png with: “Failed loading libpng16-16.dll:”

落爺英雄遲暮 提交于 2019-12-07 03:32:01

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/21472958/sdl-image-img-load-fails-on-png-with-failed-loading-libpng16-16-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!