【问题标题】:How to build SLN file from the command line using MSVC build tools如何使用 MSVC 构建工具从命令行构建 SLN 文件
【发布时间】:2018-12-01 16:54:11
【问题描述】:

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

该项目有一个 msvc 文件夹,其中包含一个 Hunspell.slnlibhunspell.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


【解决方案1】:

如何使用 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了:

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2010-11-10
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 2012-01-23
    • 2010-09-08
    • 1970-01-01
    相关资源
    最近更新 更多