如何使用 MSVC 构建工具从命令行构建 SLN 文件
How to build SLN file from the command line using MSVC build tools
我正在尝试使用 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]
上面的重要部分如下: 无法打开包含文件:'windows.h'
在查看 INCLUDES 变量时,我的控制台似乎设置正确:
echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\VC\Tools\MSVC.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\include\um;C:\Program Files (x86)\Windows Kits\include.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\include.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\include.0.17763.0\um;C:\Program Files (x86)\Windows Kits\include.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\include.0.17763.0\cppwinrt
我尝试了很多选项,例如 运行,如下所示,但没有成功:
> msbuild libhunspell.vcxproj /p:AdditionalIncludeDirectories="C:\Program Files (x86)\Windows Kits\Include.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 编译器进行构建。
How to build SLN file from the command line using MSVC build tools
您应该通过构建工具安装各个组件 VC++ 2015.3 v14.00 (v140) toolset for desktop
。
根据错误日志:
TargetFrameworkVersion or PlatformToolset may be set to an invalid
version number
当我们用记事本打开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
。为此,打开构建工具,切换到 Individual components 选项卡和 select VC++ 2015.3 v14.00 (v140) toolset for desktop
:
之后,我就可以成功构建peoject了:
希望对您有所帮助。
我正在尝试使用 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]
上面的重要部分如下: 无法打开包含文件:'windows.h'
在查看 INCLUDES 变量时,我的控制台似乎设置正确:
echo %INCLUDE%
C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\VC\Tools\MSVC.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK.6.1\include\um;C:\Program Files (x86)\Windows Kits\include.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\include.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\include.0.17763.0\um;C:\Program Files (x86)\Windows Kits\include.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\include.0.17763.0\cppwinrt
我尝试了很多选项,例如 运行,如下所示,但没有成功:
> msbuild libhunspell.vcxproj /p:AdditionalIncludeDirectories="C:\Program Files (x86)\Windows Kits\Include.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 编译器进行构建。
How to build SLN file from the command line using MSVC build tools
您应该通过构建工具安装各个组件 VC++ 2015.3 v14.00 (v140) toolset for desktop
。
根据错误日志:
TargetFrameworkVersion or PlatformToolset may be set to an invalid version number
当我们用记事本打开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
。为此,打开构建工具,切换到 Individual components 选项卡和 select VC++ 2015.3 v14.00 (v140) toolset for desktop
:
之后,我就可以成功构建peoject了:
希望对您有所帮助。