0

I am trying to use sdl2-image, but I get the following error:

Failed Error: Failed loading libpng16.dll: The specified module could not be found.

Using:

#include <iostream>
#include "SDL2/SDL_image.h"

int main(int argc, char* args[]) {
    if (!(IMG_Init(IMG_INIT_PNG))) std::cout << "Failed Error : " << SDL_GetError() << std::endl;
    return 0;
}

I am using Visual Studio compiler with ninja build system and vcpkg in clion.

There should be no error when using IMG_Init but I keep geting the error.

James Risner
  • 5,451
  • 11
  • 25
  • 47
Rohit
  • 1
  • 3
  • dll is present in the vcpkg folder but the project is not able to find it. – Rohit Dec 18 '22 at 05:37
  • You may also need the zlib dll. [SDL_Image IMG_Load fails on png with: "Failed loading libpng16-16.dll:"](https://stackoverflow.com/questions/21472958/sdl-image-img-load-fails-on-png-with-failed-loading-libpng16-16-dll) – Retired Ninja Dec 18 '22 at 05:37
  • zlib dll is also present in the vcpkg folder but I still get the error I also tried the solution from here SDL_Image IMG_Load fails on png with: "Failed loading libpng16-16.dll:" – Retired Ninja. but no success. – Rohit Dec 18 '22 at 05:41
  • @Rohit and do windows know anything about this "vcpkg folder"? If it isn't in the PATH, it wouldn't look there when searching for dlls. "Usual" approach is to put dlls in either the same directory your executable is located in, or into system directory. – keltar Dec 18 '22 at 05:49
  • @keltar yes, the vcpkg folder is in the PATH and also I tried to put dlls in cmake-build-debug folder where the executable is located. – Rohit Dec 18 '22 at 06:14
  • @Rohit make sure your executable and dlls are targeting the same CPU architecture . Try loading your dll into dependency walker (the same dll that you're loading - which is in your executable' directory) to check if all dependencies are met. – keltar Dec 18 '22 at 06:30

0 Answers0