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;
}
In MSVC, there are two main types of errors,
C
which states that its a compiler error.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.