静态链接MSVC库,动态链接Qt [英] Statically link MSVC libraries, dynamically link Qt

查看:55
本文介绍了静态链接MSVC库,动态链接Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署我用 Qt 构建的东西,由于 LGPL,它是动态链接的.我使用 windeployqt.exe 来收集必要的 dll,它在 Windows 10 机器上运行良好.当我在 Windows 7 机器上尝试时,出现此错误:

I was deploying something I built with Qt, and it was dynamically linked because of LGPL. I used windeployqt.exe to collect necessary dlls, and it was working fine on Windows 10 machines. When I tried on a Windows 7 machine, I got this error:

程序无法启动,因为您的计算机缺少 MSVCP140.dll.

The program can't start because MSVCP140.dll is missing from your computer.

经过一番研究,发现 MSVCP140.dll 是 Visual Studio 安装的 System 32 中的 dll.我应该让我的客户安装 Visual Studio,这在我的情况下不是一个选项,或者静态链接它.我尝试使用 /MT 但我得到了:

After a little research, it turns out that MSVCP140.dll is a dll in System 32 that Visual Studio installs. I should either have my clients install Visual Studio, which is not an option in my case, or statically link it. I tried using /MT but I got:

用/MD 覆盖/MT

大概是因为我不能在不静态编译 Qt 本身的情况下静态链接 Qt 库.我想做的是动态链接 Qt 库,因为 LGPL,并静态链接 MSVC 库.有没有办法做到这一点?最好来自 Qt 创建者.
我认为在程序中包含 MSVCP140.dll 不是一种选择.

Presumably because I can't statically link Qt libraries without compiling Qt itself statically. What I want to do is dynamically link Qt libraries, because of LGPL, and statically link MSVC libraries. Is there a way to do that? Preferably from the Qt creator.
I think including MSVCP140.dll with the program is not an option.

我使用的是 Visual Studio 2019 和 Qt 13.1

I am using Visual Studio 2019 and Qt 13.1

推荐答案

为了让目标机器运行使用 Visual Studio 2015 或更高版本构建的软件,您需要在其上安装最新的 MSVC 运行时可再发行包.某些系统(例如 Windows 10)已经有足够新的版本.

In order for a target machine to run software built with Visual Studio, 2015 or later, you will need to install the latest MSVC run-time redistributable pack on it. Some systems (e.g. Windows 10) will already have a recent-enough version.

您可以从这里获取最新的包:vc_redist.XXX.exe 取决于目标平台.

You can get the latest packs from here: vc_redist.XXX.exe depending on the target platform.

选择静态链接"选项仅适用于 MFC 库.

Selecting the "Link Statically" option only applies to the MFC libraries.

有一个旧的 - 但可能很有帮助 - Q &关于堆栈溢出的此处.

There is an old - but possibly quite helpful - Q & A here on Stack Overflow.

这篇关于静态链接MSVC库,动态链接Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆