我正在构建一个C ++库(标头集,导入库和DLL)。我想让任何想要使用它的开发人员尽可能地使用这个库。特别是我不希望这个库的使用者不必担心为项目的所有不同配置(Debug | Release和x86 / x64 / ARM)手动更改头路径,库路径和链接库。我知道我可以使用属性表来做到这一点。我为此创建了6个不同的属性表(每个配置一个)。每个工作表如下所示(仅列出x86 | Debug版本,假设正确定义了宏INCLUDEPATH和LIBPATH):
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_PropertySheetDisplayName>MyCPPLib, 1.0</_PropertySheetDisplayName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$INCLUDEPATH;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(AdditionalLibraryDirectories);$LIBPATH\x86\Debug</AdditionalLibraryDirectories>
<AdditionalDependencies>MyCPPLib.lib;$(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
我想知道是否可以创建一个可以根据用户的活动配置处理所有6种配置的道具文件? 该文件将如何显示?
答案 0 :(得分:3)
您可以在以下结构中安装库二进制文件:
<toplevelsdkdir>
|-> lib
|-> x86
|-> Debug
|-> Release
|-> x64
|-> Debug
|-> Release
然后只需创建一个像这样的项目范围的道具文件:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_PropertySheetDisplayName>MyCPPLib, 1.0</_PropertySheetDisplayName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$INCLUDEPATH;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(AdditionalLibraryDirectories);$LIBPATH\$(PlatformTarget)\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>MyCPPLib.lib;$(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
如果您可以,您可以将变量INCLUDEPATH和LIBPATH替换为从注册表中读取的信息(您可以在安装期间放置它):
<ClCompile>
<AdditionalIncludeDirectories>$([MSBuild]::GetRegistryValue(`HKEY_LOCAL_MACHINE\Software\MyCompany\MySDK\v1`, `InstallDir`))\INCLUDE;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>