如何避免`msvcrt.dll`与MinGW64一起编译? [英] How to Avoid `msvcrt.dll` Compiling with MinGW64?

查看:469
本文介绍了如何避免`msvcrt.dll`与MinGW64一起编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些可以编译到各种平台上的C ++代码,即Linux 32/64位,Windows 32/64位.对于Windows,我使用mingw-w64软件包提供的最新gcc编译器.我遇到的麻烦是32位编译拖累了Microsoft通过msvcrt.dll提供的libc API,并且该DLL存在一些问题:

I have some C++ code that I compile to various platforms, namely Linux 32/64 bits, Windows 32/64 bits. For the Windows part, I use the latest gcc compiler provided by mingw-w64 package. The trouble I am having is that the 32-bit compilation drags the libc API that Microsoft provides through msvcrt.dll, and that DLL has some problems:

  1. 不可分发(它是Windows附带的,不可替换)
  2. 有版本(每个Windows版本都有一个不同的版本,具有附加功能)
  3. 它依赖于其他Windows DLL,这意味着该特定版本的DLL周围的库生态系统也属于该系统.

mingw使用特定版本,因此默认情况下不会在较早版本上运行,例如在Windows XP中:它将需要不存在的API的入口点.

mingw uses a specific version, so it won't run by default on older versions, for example in Windows XP: it will require entry points to non-existent APIs.

我尝试了静态链接,但无济于事,msvcrt.dll总是被拖拽(-static,-static-libgcc,-static-libstdc ++,您为它命名).

I tried linking statically, but to no avail, msvcrt.dll always gets dragged (-static, -static-libgcc, -static-libstdc++, you name it).

我相当坦率地尝试将Windows XP附带的msvcrt.dll替换为可在较新的Windows版本中运行的msvcrt.dll,但该操作完全阻止了Windows XP的启动.

I tried, rather candidly, replacing the msvcrt.dll that comes with Windows XP with one that works in a more recent Windows version, but that prevents Windows XP from booting at all.

我尝试将正确的msvcrt.dll复制到我的可执行路径,但是由于它是每个人都使用的库,因此已经加载并且Windows不会从其他文件加载另一个实例.

I tried copying the correct msvcrt.dll to my executable path, but as it is a library everybody uses, it's already loaded and Windows won't load another instance from a different file.

我尝试修补可执行文件,以便它将调用相同的DLL,但使用不同的名称,因此愚蠢的Windows仅为我的可执行文件加载较新的版本,并且第一步有效,但它开始了对DLL依赖项的噩梦,永远无法满足,因为它将引入其他系统库,例如ntdll.dll,这些系统库也必须进行修补等等.

I tried patching my executable so it will call the same DLL but with a different name and so fool Windows to load a more recent version only for my executable, and that first step works, but it starts a nightmare of DLL dependencies that can never be satisfied, because it will bring in other system libraries like ntdll.dll that also have to be patched and so on.

我尝试在此处以及在不同的论坛中浏览有关此相同问题的几个问题,但是所有内容都归结为msvcrt.dll是一个您不必担心的库,但这根本不是事实,那里有很多兼容性问题.

I tried browsing through several questions on this topic here and in different forums regarding this same problem, but everything boils down to the idea that msvcrt.dll is a library that you should not worry about, but that is simply not true, there is a plethora of compatibility problems about it.

我知道mingw逐渐抛弃了Windows XP等较旧的操作系统,但是我真的很想找到一个解决问题的方法,这个问题应该看起来并不那么复杂.我首先将mingw-w64-i686-libwinpthread和mingw-w64-i686-winpthreads从当前的7.0.0.5325降级到相距不远的7.0.0.5273,以避免调用GetTickCount64(),这是Vista中引入的API.修复此问题后,它会要求我从msvcrt.dll中提供_mkgmtime32(),该DLL是在DLL的版本7中引入的,而Windows XP随附的DLL中显然没有该_mkgmtime32().

I am aware that mingw is slowly leaving behind older operating systems like Windows XP, but I would really like a solution to a problem that should not to be as complicated as it seems. I started by downgrading mingw-w64-i686-libwinpthread and mingw-w64-i686-winpthreads from the current 7.0.0.5325 down to a not so far away 7.0.0.5273 to avoid a call to GetTickCount64(), an API introduced in Vista. Once I fixed that, it asks me for _mkgmtime32(), from msvcrt.dll, that was introduced in version 7 of the DLL, and that obviously is not present in the DLL that comes with Windows XP.

我也知道我想将C ++ 17与已经有近20年历史的操作系统一起使用,但是它仍然非常流行,至少在第三世界中仍然如此.有人对此有任何见识吗?

I am aware as well that I want to use C++17 with an operating system that is almost 20 years old, but it is overwhelmingly popular still, at least in the third world. Anyone has any insight about this?

使用MinGW64时是否可以链接到静态多线程VC运行时库?
使用MinGW64时,Visual Studio中/MT标志的等效项是什么?

Is there a way to link to the static multi threaded VC Runtime Library when using MinGW64?
What's the equivalent of /MT flag in visual Studio when using MinGW64?

推荐答案

  1. 最新的Visual Studio 2019仍支持带有特殊vc141_xp工具集"的Windows XP.您可以重新分发 XP上的最新通用CRT".
  2. MinGW能够与通用CRT 链接-您完全不需要使用旧的msvcrt.dll,您可以按照上面的链接所述与任何msvcrXX.dll或现代ucrtbase.dll链接,并且它可以在Windows XP上运行.
  1. Latest Visual Studio 2019 still supports Windows XP with special vc141_xp "toolset". You are able to redistribute latest "Universal CRT" on XP.
  2. MinGW is able to link with Universal CRT - you no need to use old msvcrt.dll at all, you can link with any msvcrXX.dll or modern ucrtbase.dll as described on link above and it will work on Windows XP.

这篇关于如何避免`msvcrt.dll`与MinGW64一起编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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