静态链接所有依赖项,以便最终用户永远不会被要求安装 vc_redist.exe
我正在使用 VS 2019 构建一个 Windows 可执行文件。当我在我的计算机上运行它时,它可以工作,但我不能 100% 确定它是否适用于没有 vc_redist.x64.exe< 的最终用户/code> 版本 2019。(特别是 Win7 上的用户 - 它处于用户仍然使用此版本的利基市场)。
如何静态链接所有内容,以便最终用户永远不会被要求下载和安装 Visual C++ Redistributable "vc_redist"?
我正在使用 msbuild.exe
,并且没有 IDE。 要在 .vcxproj
文件或 .cpp
文件中添加哪个设置来启用完全静态链接,以防止需要 vcredist?
我的.cpp 代码需要这些库:
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "winmm.lib")
示例 .vcxproj:
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />
</Project>
注意:它与主题 如何将 Win32 API 应用程序部署为可执行文件 ,但这里是直接从 .vcxproj
文件执行此操作,无需 IDE。
I'm building a Windows executable with VS 2019. When I run it on my machine, it works, but I'm not 100% sure it will work for end users who don't have vc_redist.x64.exe
version 2019. (Especially users on Win7 - it's in a niche where users still use this version).
How to statically link everything so that the end user will never be asked to download and install Visual C++ Redistributable "vc_redist"?
I'm using msbuild.exe
, and no IDE. Which setting to add in the .vcxproj
file or in the .cpp
file to enable full static linking, to prevent the need for vcredist?
My .cpp code asks for these libraries:
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "winmm.lib")
Sample .vcxproj:
<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.default.props" />
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Targets" />
</Project>
Note: it is linked with the topic How to deploy a Win32 API application as an executable, but here it's about doing it specifically directly from the .vcxproj
file and without the IDE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为编译配置添加特定的 ClCompile 属性:
可能的值如下: runtimeLibraryOption 枚举
(删除“rt”前缀)
有关 MT / MD 的更多信息可以在这里找到:/MD、/MT、 /LD(使用运行时库)
Add a specific ClCompile property for the compilation configuration:
Possible values are here: runtimeLibraryOption Enum
(remove the "rt" prefix)
More info about MT / MD can be found here: /MD, /MT, /LD (Use Run-Time Library)