Reputation: 151
I am creating a solution that requires the use of libpng. I installed this library and its dependencies through Visual Studio 2019's Nuget Package Manager, and including <png.h> and using functions and macros from the library does not lead to errors. However, should I try building the solution, I get one LNK2019 error per every reference to the library function or variable. It seems to me that NuGet failed to add the library locations to the linker properties. I have found where are the .lib files located, but I'm lost as to which settings do I adjust so that the Studio looks for, and finds, these files in the NuGet directory.
Upvotes: 2
Views: 799
Reputation: 23808
The issue why the automatic nuget cannot add the lib dependencies into the Linker is that the c++ nuget is for v140
and v120
build tool. And if your project is created by VS2019, VS uses v142
build tool(for VS2019) by default.
You can check the targets
file(Methods to import lib automatically) from the nuget package <solution_folder>\packages\libpng.1.6.28.1\build\native\libpng.targets
.
So this file cannot find V140
and V120
,(your VS2019 uses V142
) make the condition to false, so that auto import lib fails forever. That is the reason.
V140 is VC++2015 build tool
while V120 is VC++ 2013 build tool
.
If your PC has installed VS2015 and VS2013, you can change build tool for VS0219 by right-click on the project Properties-->Configuration Properties-->General--> change Platfrom Toolset to Visual Studio 2015(v140).
And if your PC only has VS2019 and also for a better workaround,
You should install libpng-v142 nuget package instead and it is for VS2019 VC++.
Upvotes: 1