提问人:Alexandre St-amant 提问时间:11/27/2017 最后编辑:valianoAlexandre St-amant 更新时间:12/20/2017 访问量:961
Nuget - 使用链接到 nuget 包的项目之一时LNK2019
Nuget - LNK2019 when using one of my project that links to a nuget package
问:
好的,我的问题很简单,但我搞不通。
在一个解决方案中,我有一个引用另一个项目(lib)的项目(Application exe)。此库引用 nuget 包,例如 CxImage。
。目标
<?xml version="1.0" encoding="utf-8"?>
<Project ToolVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>"$(MSBuildThisFileDirectory)include";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<!-- patch -->
<AdditionalIncludeDirectories>"$(MSBuildThisFileDirectory)include\cximage";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('release')) And '$(Platform.ToLower())'=='x64'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage.lib;jpeg.lib;png.lib;tiff.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('debug')) And '$(Platform.ToLower())'=='x64'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage_d.lib;jpeg_d.lib;png_d.lib;tiff_d.lib;zlib_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('release')) And '$(Platform.ToLower())'=='win32'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage.lib;jpeg.lib;png.lib;tiff.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('debug')) And '$(Platform.ToLower())'=='win32'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage_d.lib;jpeg_d.lib;png_d.lib;tiff_d.lib;zlib_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)lib\x86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
在构建引用此库的另一个项目时,它会导致LNK2019未解析的外部符号“public: __thiscall CxImage::CxImage(unsigned int)” (??0CxImage@@QAE@I@Z) 函数中引用
表示它找不到 cxImage 的 lib 文件。
我找到了解决问题的方法,但我认为这是不对的。 在其他应用程序中使用的库属性中,在 Librarian > General > Additionnal Dependencies 中,我添加了 cxImage lib。虽然 nuget 包背后的第一个想法是避免这种事情,所以......
** 它与 cxImage 无关,问题发生在任何其他情况下。例如,我刚刚提到了这个
任何想法??^^
答:
Nuget - 使用链接到 nuget 包的项目之一时LNK2019
还应将 nuget 包添加到参考项目。CxImage
项目引用 和 引用 nuget 包,因此项目不直接引用 nuget 包,Visual Studio/MSBuild 尝试智能,仅将引用引入项目,而不是将 nuget 包添加到项目中。因为 Visual Studio/MSBuild 不知道间接引用 CxImage
是否是项目所必需的。因此,Visual Studio/MSBuild 不会将 nuget 包添加到引用项目中,以避免引用污染项目。有关详细信息,请参阅类似问题。lib
lib
CxImage
CxImage
lib
CxImage
在这种情况下,您将收到错误“找不到cxImage的lib文件”。若要解决此问题,还应将 nuget 包添加到引用项目中,以便 projest 直接引用 nuget 包。CxImage
CxImage
评论