1

我正在尝试使用 MSVC 2017 构建工具在 GitHub 上构建 Hunspell 项目: https ://github.com/hunspell/hunspell

该项目有一个msvc包含一个Hunspell.slnlibhunspell.vcxproj文件的文件夹(我对库感兴趣)

我的设置:

  • 视窗 10
  • MSVC2017 构建工具 (15.9.3)
  • Windows 10 套件:10.0.17763.0

如果我打开“x86 Native Tools Command Prompt for VS 2017”并尝试构建解决方案,我会收到以下错误:

>msbuild libhunspell.vcxproj
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 2018/12/01 6:01:18 PM.
Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
InitializeBuildStatus:
  Touching "Debug\libhunspell\libhunspell.tlog\unsuccessfulbuild".
PreBuildEvent:
  echo N | copy /-Y ..\src\hunspell\hunvisapi.h.in ..\src\hunspell\hunvisapi.h
  :VCEnd
  Overwrite ..\src\hunspell\hunvisapi.h? (Yes/No/All): N
          0 file(s) copied.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /I..\src\hunspell /I. /ZI /nologo /W4 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _WINDOWS /D _USRDLL /D HUNSPELL_STATIC /D _CRT_SECURE_NO_WARNINGS /D _USING_V110_SDK71_ /D_MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\libhunspell\\" /Fd"Debug\libhunspell\libhunspell.pdb" /Gd /TP /wd4706 /wd4251 /wd4267 /analyze- /errorReport:queue ..\src\hunspell\csutil.cxx 
csutil.cxx
c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]
Done Building Project "c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default targets) -- FAILED.


Build FAILED.

"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(CheckWindowsSDK71A target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Win32\PlatformToolsets\v140_xp\Toolset.targets(36,5): warning MSB8003: Could not find WindowsSdkDir_71A variable from the registry.  TargetFrameworkVersion or PlatformTool set may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]


"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(PrepareForBuild target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]


"c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj" (default target) (1) ->
(ClCompile target) ->
  c:\development\hunspell\hunspell-1.7.0\src\hunspell\csutil.cxx(84): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [c:\Development\Hunspell\hunspell-1.7.0\msvc\libhunspell.vcxproj]

上面的重要部分如下:无法打开包含文件:'windows.h'

查看 INCLUDES 变量时,我的控制台似乎设置正确:

echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt

我尝试了许多选项,例如按以下方式运行,但没有运气:

> msbuild libhunspell.vcxproj /p:AdditionalIncludeDirectories="C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um"

我还在vcxproj 文件中手动将“um”和“shared”(for winapifamily.h)文件夹的完整路径添加到属性中。<AdditionalIncludeDirectories>这适用于静态库,但我必须将其添加<AdditionalIncludeDirectories><ResourceCompile>步骤中。对于 dll(Release_Dll等)链接不起作用,因为我不知道如何解决这个问题(还)。
上面感觉不对,我不认为解决方案可以是破解一个项目文件让编译器知道它自己的文件在哪里。

在这方面的任何帮助将不胜感激。

注意:我没有安装 Visual Studio IDE,围绕这个问题的大多数 SO 问题都涉及通过更改 Visual Studio 中的设置来解决问题的步骤。这不适用于这个问题。

PS:我没有使用 msbuild 或构建工具的经验。我通常使用 Qt Creator IDE 来构建 MSVC 编译器。

4

1 回答 1

5

如何使用 MSVC 构建工具从命令行构建 SLN 文件

VC++ 2015.3 v14.00 (v140) toolset for desktop您应该通过构建工具安装各个组件。

根据错误日志:

TargetFrameworkVersion 或 PlatformToolset 可能设置为无效的版本号

当我们libhunspell.vcxproj用记事本打开时,我们可以知道以下属性:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug_dll|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <PlatformToolset>v140_xp</PlatformToolset>
    <UseOfMfc>false</UseOfMfc>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>

因此,要解决此问题,我们需要安装工具集v140_xp。为此,打开构建工具,切换到单个组件选项卡并选择VC++ 2015.3 v14.00 (v140) toolset for desktop

在此处输入图像描述

之后,我可以成功构建peoject:

在此处输入图像描述

希望这可以帮助。

于 2018-12-03T07:07:23.080 回答