I am trying to link my project against the libpng version 1.6.23 dll library, but my linker only sees all function calls that I make to it as unresolved external symbols. I am using Visual Studio Express 2013. Here is a snippet of the linker's output.
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_sig_bytes referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_sig_cmp referenced in function "private: static bool __cdecl PNGUtils::Validate(struct _iobuf *)" (?Validate@PNGUtils@@CA_NPEAU_iobuf@@@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_create_read_struct referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_longjmp_fn referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_create_info_struct referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_read_info referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
1>PNGUtils.obj : error LNK2019: unresolved external symbol png_set_expand_gray_1_2_4_to_8 referenced in function "public: static void * __cdecl PNGUtils::Read(char const *,unsigned int &,unsigned int &,int &)" (?Read@PNGUtils@@SAPEAXPEBDAEAI1AEAH@Z)
I am linking successfully with other libraries such as lua and glew, and I am to my knowledge doing nothing different when trying to link to libpng.
Strangely, when I put the linker into verbose mode. It states...
1> Finished searching libraries
1>
1> Unused libraries:
1> libs\png\libpng16.lib
The linker seems to claim that I am not using the libpng library even though I am clearly calling its functions such as in my code segment here in PNGUtils.cpp Read method.
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!pngPtr)
{
LOG(LOG_CHANNEL_ERROR, "PNGUtils: Couldn't initialize png read struct");
fclose(fp);
return NULL;
}
png_infop infoPtr = png_create_info_struct(pngPtr);
if (!infoPtr)
{
LOG(LOG_CHANNEL_ERROR, "PNGUtils: Couldn't initialize png info struct");
png_destroy_read_struct(&pngPtr, (png_infopp)0, (png_infopp)0);
fclose(fp);
return NULL;
}
I feel lost on why the linker seems to be ignoring the function calls to libpng. I would be happy to hear any thoughts or answers and am of course more than willing to provide any more information on request.
Be sure that your project and your libpng.dll were built with the same settings, as explained in the projects/vstudio/README.txt that comes with libpng:
WARNING ======= Libpng 1.6.x does not use the default run-time library when building static library builds of libpng; instead of the shared DLL runtime it uses a static runtime. If you need to change this make sure to change the setting on all the relevant projects:
libpng zlib all the test programs
The runtime library settings for each build are as follows:
Release Debug DLL /MD /MDd Library /MT /MTd
NOTICE that libpng 1.5.x erroneously used /MD for Debug DLL builds; if you used the debug builds in your app and you changed your app to use /MD you will need to change it back to /MDd for libpng 1.6.0 and later.
The Visual Studio 2010 defaults for a Win32 DLL or Static Library project are as follows:
Release Debug DLL /MD /MDd Static Library /MD /MDd
Also, be sure to build libpng, zlib, and your project all for the same platform (e.g., 32-bit or 64-bit).