3

I'm trying to write a simple PNG file using libpng in C using VS2013. I installed libpng from Nuget and included png.h, but I can't compile. I get this as my output:

1>main.obj : error LNK2019: unresolved external symbol png_create_write_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_longjmp_fn referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_create_info_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_write_info referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_destroy_write_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_init_io referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_free_data referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_IHDR referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_text referenced in function writeImage

I've tried playing with the compilation settings, but nothing seems to make it work. I don't get any red lines under any of those declarations when I write the code, so VS must be seeing some of the code.

Shawn Walton
  • 1,714
  • 2
  • 14
  • 23

1 Answers1

1

Besides including png.h you must also link with the appropriate import library (probably called libpng.lib or something similar). In Visual Studio, you would add this to Project Settings → Linker → Input → Additional Dependencies.

Rufflewind
  • 8,545
  • 2
  • 35
  • 55
  • Actually in this case it's not a problem about a missing library - the idea behind NuGet is that (like `pkg-config` under Linux) the libraries to link are included automatically. In this case the most likely problem is that the NuGet package needs to be updated for a new toolset version (so it isn't supplying any library filenames because it doesn't recognise the current toolset.) This seems to happen when using a version of Visual Studio newer than the package. I posted an answer at the above duplicate question with details on how to do this. – Malvineous Jan 17 '15 at 02:26