Nuget - LNK2019使用我链接到nuget包的项目之一
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nuget - LNK2019使用我链接到nuget包的项目之一相关的知识,希望对你有一定的参考价值。
好吧,我的问题很简单,但我无法弄明白。
在单个解决方案中,我有一个引用另一个(lib)的项目(Application exe)。该lib引用了一个nuget包,例如CxImage。
.targets
<?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)includecximage";%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('release')) And '$(Platform.ToLower())'=='x64'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage.lib;jpeg.lib;png.lib;tiff.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('debug')) And '$(Platform.ToLower())'=='x64'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage_d.lib;jpeg_d.lib;png_d.lib;tiff_d.lib;zlib_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('release')) And '$(Platform.ToLower())'=='win32'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage.lib;jpeg.lib;png.lib;tiff.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="$(Configuration.ToLower().StartsWith('debug')) And '$(Platform.ToLower())'=='win32'">
<Lib>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Lib>
<Link>
<AdditionalDependencies>CxImage_d.lib;jpeg_d.lib;png_d.lib;tiff_d.lib;zlib_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>"$(MSBuildThisFileDirectory)libx86";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
在构建引用此lib的其他项目时,它会导致LNK2019未解析的外部符号“public:__thiscall CxImage :: CxImage(unsigned int)”(?? 0CxImage @@ QAE @ I @ Z)在函数中引用
意味着它无法找到cxImage的lib文件。
我找到了解决问题的方法,但我不认为这是正确的。在其他应用程序中使用的lib的属性中,在Librarian> General> Additionnal Dependencies中,我添加了cxImage lib。我认为nuget包背后的第一个想法是避免这种事情......
**它与cxImage无关,在任何其他情况下都会出现问题。我刚刚提到过这个
任何的想法 ?? ^^
Nuget - LNK2019使用我链接到nuget包的项目之一
您还应该将nuget包CxImage
添加到参考项目中。
项目引用lib
和lib
引用nuget包CxImage
,因此项目不直接引用nuget包CxImage
,Visual Studio / MSBuild试图变得聪明并且只将引用lib
引入项目而不是将nuget包CxImage
添加到项目中。因为Visual Studio / MSBuild不知道间接引用CxImage
是否需要项目。因此Visual Studio / MSBuild不会将nuget包添加到参考项目中以避免参考污染项目。您可以参考similar issue获取详细信息。
在这种情况下,您将收到“无法找到cxImage的lib文件”的错误。要解决此问题,您还应该将nuget包CxImage
添加到参考项目中,以便projest直接引用nuget包CxImage
。
以上是关于Nuget - LNK2019使用我链接到nuget包的项目之一的主要内容,如果未能解决你的问题,请参考以下文章
无法链接 GLFW C++;添加了 .dll、.h、.lib,但仍然获得 LNK2019