为什么 MinGW 很慢?
我正在 Windows 上使用带有 GCC/MinGW 的 Code::Blocks IDE,并且我正在尝试构建一个具有 ca 的 wxWidgets 应用程序。 20k 行和 40 个源模块。 而且它的构建速度非常非常慢。
编译一个C++模块需要2-5秒,链接甚至需要2-3分钟。
它是可移植的代码,并且该代码在 Linux 上编译得非常快。 我无法跟踪构建消息窗口...整个过程持续不到 20 秒。
我尝试了常见的调整(例如,预编译头、关闭优化等),但没有任何效果。
为什么这么慢?
I'm using the Code::Blocks IDE with GCC/MinGW on Windows, and I'm trying to build a wxWidgets application which has ca. 20k lines and 40 source modules. And it builds very very slow.
Compiling a C++ module lasts 2-5 seconds, and linking lasts even 2-3 minutes.
It's a portable code, and this code compiles very fast on Linux. I can't follow the build message window... The entire process lasts less than 20 seconds.
I tried the common tweaks (for example, precompiled header, turn optimizations off, etc.), but nothing worked.
Why is it so slow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MinGW 上的许多“unixy”东西都慢得令人痛苦,因为 Windows 没有
fork()
。 Windows只有CreateProcess()
,这是完全不同的。 Unix shell 和 GNU Make 进行了大量的分叉,因此在 MinGW 下运行这些会导致“模拟”分叉,这非常慢。另一个受此困扰的是 GNU Autotools,因此在从源代码构建“unixy”应用程序时运行
./configure
脚本也非常慢。 如果您需要多次执行此操作(例如在配置配置以查找所有库时遇到困难),这可能会变得非常烦人。这个答案更详细地解释了 Cygwin 和 MinGW 如何用来模拟
fork()
,并且这个答案有更多最新的解释。Many "unixy" things on MinGW are painfully slow, because Windows has no
fork()
. Windows only hasCreateProcess()
, which is quite different. Unix shells and GNU Make do a lot of forking, so running these under MinGW results in "emulated" forks, which are really slow.Another thing which suffers from this is GNU Autotools, so running
./configure
scripts when building "unixy" applications from sources is also very slow. This can get really annoying if you need to do it many times (for example when having troubles with with getting configure to find all the libraries).This answer explains in more detail how Cygwin and MinGW used to simulate
fork()
, and this answer has more up to date explanation.您可以尝试使用该工具集的更新版本。 我发现这很有用:
http://nuwen.net/mingw.html
它在一个大包中包含 MinGW 使用的所有工具和通用 API。
从网站:
You can try to use a more recent version of the toolset. I found this to be useful:
http://nuwen.net/mingw.html
It has all the tools used by MinGW and common APIs in a single big package.
From the site:
您是否位于 Active Directory 域中,但未立即连接到该域?
虽然我不知道为什么 MinGW 会很慢,但根据我的经验,属于 AD 域但无法到达 AD 控制器的计算机在启动可执行文件时会出现延迟(例如rxvt.exe)和当前正在运行的程序会遇到暂停或卡顿(例如使用 MinGW 构建的 emacs)。
我仍在调查以确定此行为的实际原因,但我想我会提及它,以防它适用于您。
Are you on an Active Directory domain, but not immediately connected to it?
While I don't have the "answer" as to why MinGW would be slow, it has been my experience that computers which belong to an AD domain, but are unable to reach the AD controller, have a delay in starting executables (such as rxvt.exe) and currently running ones experience a pause or stutter (such as emacs, which is built using MinGW).
I am still investigating to determine the actual cause of this behavior, but thought I would mention it in case it applies to you.
从
MSYS 1.0.19-1
开始,如果用户帐户位于 Active Directory 域中并且无法访问域控制器 (DC),则MSYS DLL
将引入较长的延迟在启动任何 MSYS 可执行文件(使用 MSYS DLL)之前。 这会影响 MSYS make 以及 CoreUtils 包中的所有命令行实用程序,例如通常安装在 C 中的 ls 、 rm 等:\MinGW\msys\1.0\bin。观察结果:
当从 MSYS
bash
shell 启动实用程序时,只有 shell 的启动受到延迟影响。 从 shell 启动的实用程序不会受到影响。延迟可能会有所不同,在我的例子中为 21 秒。
cmd
并输入echo %LOGONSERVER%
,然后使用ping
或net view
DC 的主机名。为什么这么慢:
uinfo.ccInternal_getlogin()
中MSYS DLL
的代码进行了两次系统调用来获取用户信息。 第一次调用NetUserGetInfo()
从本地计算机检索用户帐户。 它对于域用户失败,因此它使用从 LOGONSERVER 变量获取的 DC 服务器第二次调用它。 如果不能立即访问该主机,则会引入很长的延迟,直到调用超时失败。 该应用程序将很快开始。如何避免此问题,有几种解决方法:
LOGONSERVER
。cmd
或脚本调用 MSYS 工具,请将LOGONSERVER
设置为本地主机以避免网络访问。 例如set LOGONSERVER=\\LOCALHOST
对我有用。 注意:此变量是在登录时设置的,与在cmd
或脚本中设置相比,在 Windows 环境变量窗口中全局更改它没有效果。As of
MSYS 1.0.19-1
, if the user account is in Active Directory domain and the Domain Controller (DC) is unreachable, thenMSYS DLL
will introduce a long delay before starting any MSYS executable (that usesMSYS DLL
). This affects MSYSmake
and all the command-line utilities from CoreUtils package such asls
,rm
etc that are typically installed inC:\MinGW\msys\1.0\bin
.Observations:
When launching utilities from MSYS
bash
shell, only the shell's startup is hit by the delay. Utilities launched from the shell are not impact.The delay can vary, in my case it is 21sec.
cmd
and typeecho %LOGONSERVER%
, thenping
ornet view
with the host name of the DC.Why is it so slow:
MSYS DLL
inuinfo.cc internal_getlogin()
makes two system calls to get user information. First time it callsNetUserGetInfo()
to retrive the user account from the local machine. It fails for domain users, so it calls it second time with the DC server taken fromLOGONSERVER
variable. If this host is not immediately accessible, it will introduce a long delay until the call fails on timeout. The application will start shortly after.How to avoid this problem, several workarounds:
LOGONSERVER
with the correct DC host.cmd
or a script, then setLOGONSERVER
to a localhost to avoid network access. E.g.set LOGONSERVER=\\LOCALHOST
worked for me. Note: this variable is set at logon and changing it globally in Windows Environment Variables window has no effect compared to setting it incmd
or a script.