【发布时间】:2018-12-01 16:54:11
【问题描述】:
我正在尝试使用 MSVC 2017 构建工具在 GitHub 上构建 Hunspell 项目: https://github.com/hunspell/hunspell
该项目有一个 msvc 文件夹,其中包含一个 Hunspell.sln 和 libhunspell.vcxproj 文件(我对该库感兴趣)
我的设置:
- Windows 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]
上面的重要部分如下:Cannot open include file: '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”(对于winapifamily.h)文件夹的完整路径添加到<AdditionalIncludeDirectories> 属性。
这适用于静态库,但我必须将 <AdditionalIncludeDirectories> 添加到 <ResourceCompile> 步骤。
对于 dll(Release_Dll 等)链接不起作用,因为我不知道如何解决这个问题(还)。
上面感觉不对,我不认为解决办法可以是破解一个项目文件让编译器知道自己的文件在哪里。
我们将不胜感激。
注意:我没有安装 Visual Studio IDE,围绕这个问题的大多数 SO 问题都涉及通过更改 Visual Studio 中的设置来解决问题的步骤。这不适用于这个问题。
PS:我没有使用 msbuild 或构建工具的经验。我通常使用 Qt Creator IDE 来构建 MSVC 编译器。
【问题讨论】:
-
github.com/hunspell/hunspell#compiling-on-windows 听起来它的作者希望你使用非 VS C++ 工具链。
-
@LexLi 我猜该文档已过时,因为有项目文件和最近的提交说“修复 msvc 构建”。无论如何,项目文件被硬编码为使用 v140_xp 工具集。是这样安装的吗?还有关于找不到 WindowsSdkDir_71A 的警告,可能相关:不确定目标 xp 是否与拥有 Windows 10 工具包兼容
-
添加项目文件的路径,最后从命令行手动运行链接命令使其编译成功...关于如何不硬编码并让项目文件使用可用的任何建议也会有所帮助
-
在项目文件中用 $(DefaultPlatformToolset) 替换 v140_xp 字符串应该可以做到这一点。
标签: visual-studio msbuild build-tools visual-studio-2017-build-tools