0

VS beginner here!

I'm using the libpng library, which I installed via NuGet in VS 2019, for a C++ project. I have a function loadPng in renderer.h that reads a png along the lines of the manual. png.h is included. The code itself has no errors. Error message is:

LNK2019 reference to an unresolved external symbole "png_set_sig_bytes" in function ""int __cdecl loadPng(char const *,struct img_format *)" (?loadPng@@YAHPEBDPEAUimg_format@@@Z)"

for all the functions from the library.

How can I fix this or what did I mess up? (I suppose I didn't set up the library properly..)

Please ask, if you need to know any specific information.

The function:

static int loadPng(const char *filename, img_format *target) {
    FILE* fp;
    fopen_s(&fp, filename, "rb");
    if (!fp) return (ERROR);
    void* tempBuffer[8] = { 0, 0, 0, 0, 0, 0, 0, 0};
    fread(tempBuffer, 1, 8, fp);

    if (png_sig_cmp((png_const_bytep)tempBuffer, 0, 8)) return (ERROR);
.
.
.
    return 0;
}

AnonPJ
  • 45
  • 7

1 Answers1

4

In MSVC, there are two main types of errors,

  1. Errors starting with a C which states that its a compiler error.
  2. Errors starting with a LNK with states that its a linking error.

Usually errors like LNK2019 happens when the linker cannot find a library or object file. So this means that your not including the library into your linker.

To do this, go to Project Properties -> Linker -> Input -> Additional Dependencies and add the library file to it. And also go to General in the same Linker tab and add the path to the library file (eg: "C:\Libs") in Additional Library Directories.
Optionally you can add the full file path (eg: "C:\Libs\library.lib") to the Additional Dependencies in the Linker tab.

rturrado
  • 7,699
  • 6
  • 42
  • 62
D-RAJ
  • 3,263
  • 2
  • 6
  • 24
  • 1
    Seems like it resolved the Error I had, thanks! Sadly NuGet somehow fails setting up the .dll file, now I have to look into that separatly. – AnonPJ Jan 19 '21 at 18:46
  • 1
    Your welcome! Im not that familiar with Nuget but check if this would help: https://stackoverflow.com/questions/40104838/automatic-native-and-managed-dlls-extracting-from-nuget-package – D-RAJ Jan 19 '21 at 19:07
  • Thanks again, I found another solution tho. For others: I searched for the .dll files and manually copied them to \Windows\System32 and \Windows\SysWOW64. – AnonPJ Jan 19 '21 at 19:13
  • You should not really put files in either of these folders. Instead put the dll in the same folder as the executable. – drescherjm Jan 19 '21 at 20:03