快速 Qt C++在windows上编译

发布于 2024-12-09 15:35:18 字数 611 浏览 1 评论 0原文

我有一个使用 Qt 框架的大型项目,并且正在尝试找到在 Windows 安装上编译它的最快方法。

在我家里的 Linux 机器上,我使用 3 年历史的 Linux Mint 设置,具有双核(该机器已有 3 年历史,未安装 Linux Mint),使用: make -j2 两个核心都被充分使用(ish )并且编译代码的速度相对较快,从干净构建开始大约需要 10 分钟。

然而,在我的工作 Windows PC(2.0 GHz Intel Core 2 Quad (XP))上,我似乎永远无法让编译速度像我的 Linux 机器一样快。该程序的开发人员文档建议使用 Visual Studio C++,使用从 cmake 生成的项目文件,但这似乎只使用一个核心,并且需要一个多小时才能编译,而在我的 Linux 安装上大约需要 10 分钟(从干净的构建)。

我尝试过使用 jom 但即使使用所有核心,它仍然需要大约一个半小时因为它似乎只在每个核心上使用少量的 cpu。

我的旧 Linux 机器构建速度很快,但四核却在下降,这对我来说是没有意义的。

I have a large project that uses the Qt framework and am trying to find the fastest way to compile it on my Windows install.

On my linux machine at home I use 3 year old Linux Mint setup with a dual core (the machine is 3 years old not Linux Mint install), using: make -j2 both cores are used full(ish) and compiles the code relatively quick, around 10 minutes from clean build.

However on my work Windows PC which is 2.0 GHz Intel Core 2 Quad (XP) I can never seem to get the compiles to be as fast as my Linux box. The developer docs for the program recommend using Visual Studio C++ using the project file generated from cmake but that only seems to use one core and takes well over a hour to compile vs about 10 minutes (from clean build) on my Linux install.

I have tred using jom but even when using all the cores it still takes around an hour and half because it only seems to use small amounts of cpu on each core.

Doesn't make sense to me that my old Linux machine builds quick but the quad core just slumps along.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

GRAY°灰色天空 2024-12-16 15:35:18

多年来,以下内容有助于提高我们的 Windows C++ Qt 构建速度:

  1. 自定义防病毒软件的设置,以排除扫描我们的源代码、目标代码以及我们正在构建的所有标头和库的位置(Visual Studio、Qt 等)。 (有一个单独的 AV 检查会在夜间运行,以扫描那些排除的文件夹)
  2. 对各种不同 AV 包下的构建速度进行比较。 (这是几年前的事,但结果是,我们从 McAfee 迁移到 Sophos)
  3. 确保构建过程中访问的所有文件都位于本地磁盘驱动器上(我们曾经在网络驱动器上针对 Qt 进行构建,但这会终止构建)性能)
  4. 确保 Visual Studio 配置为一次执行多个编译步骤:这个答案展示了实现这一点的各种方法。
  5. 增加 RAM 量:我们现在发现 4 GB 是绝对最小的,对于相当大的代码库
  6. 从静态链接切换到动态链接,以大大缩短链接时间。
  7. 迁移到 Visual Studio 的新版本,因为 MS 改进了性能:请参阅此 Visual Studio 2010 页面,并搜索“更快的编译”

我们的 Windows 构建仍然比 Linux 慢,但我不能说这是一个公平的比较,因为我们共享的 Linux 构建盒比 Linux 构建要慢得多。比开发者电脑的规格更高。

(顺便说一句,如果您以前没有见过它们,那么值得一读 Jeff Atwood 关于开发人员 PC 的良好配置的说法:例如 程序员权利法案)

更新: 2012 年 10 月 25 日

如果您使用的是 Visual Studio 2008,并且使用 DLL 构建,我目前不建议迁移到 Visual Studio 2010:存在不必要的重新链接依赖项的问题绝对会降低开发人员生产力的项目,至少在具有 20 个左右 .vcxproj 文件的 .sln 中:

可能有一个解决方案 - 一旦我测试过它,我会稍后更新 - 请参阅不必要的重新链接使用 Visual Studio 2010 构建时的依赖项目,其中 CORCOR 说:

如果其他人也有类似的问题:

关闭 DLL 项目的表现创建并
仅针对应用程序项目打开它会有所帮助!

对于 VS2008,这似乎没有问题。

The following have helped the speed of our Windows C++ Qt builds, over the years:

  1. Customised the settings on our anti-virus software, to exclude from scanning the locations of our Source code, object code, and all headers and libraries we are building against (Visual Studio, Qt etc). (There's a separate AV check that gets run overnight, to scan those excluded folders)
  2. Ran a comparison of build speeds under various different AV packages. (This was several years ago, but as a result, we moved from McAfee to Sophos)
  3. Made sure all files accessed during the build are on a local disk drive (we used to build against Qt on a network drive, but that killed the build performance)
  4. Made sure that Visual Studio is configured to do multiple compile steps at once: This answer shows various ways of doing that.
  5. Increased the amount of RAM: we're finding these days that 4 GB is the absolute minimum, for a sizable code base
  6. Switched from static to dynamic linking, to massively shorten link times.
  7. Moved to new versions of Visual Studio, as MS has improved performance: see this Visual Studio 2010 page, and search for 'Faster Compilation'

Our Windows builds are still slower than Linux ones, but I can't say that's a fair comparison, as our shared Linux build box is a much higher spec than developer PCs.

(As an aside, if you haven't seen them before, it's worth reading what Jeff Atwood has to say about good configurations for developer PCs: e.g. the Programmer's Bill of Rights)

Update: 25/10/2012

If you are on Visual Studio 2008, with DLL builds, I do not currently recommend moving to Visual Studio 2010: there is an issue with unnecessary re-linking of dependent projects that absolutely kills developer productivity, at least in a .sln with 20 or so .vcxproj files:

There may be a solution to this - I'll update later, once I've tested it - see Unnecessary relinks of dependent projects when building with Visual Studio 2010 where CORCOR said:

If others have a similar problem:

Turning off the manifestation creation for the DLL projects and
turning it on only for the application project helps!

With VS2008 this seemed to be no problem.

三生殊途 2024-12-16 15:35:18

这可能是一种解决方法,但我们使用 Incredibuild,它将构建分布在多台机器上,效果非常好。将我们的构建时间从 40 分钟缩短到 10 分钟。 (我们连接了 6 台开发人员 PC 来分担工作量)

This might be a bit of a workaround, but we use Incredibuild, which distributes the build across multiple machines, which works really well. Cuts down our build times from 40 to 10 minutes. (we have 6 developer PCs hooked up to share the workload)

毁我热情 2024-12-16 15:35:18

Visual Studio 可以并行编译多个项目,但每个项目都是按顺序编译的。
因此,如果您编译包含 2 个项目的解决方案,则将并行启动两个进程,但如果您只有一个项目,则只会启动一个进程,并且它将按顺序编译您的源代码。

如果您使用 MingW,您可以按照以下线程操作: http:// www.mail-archive.com/[email protected]/msg00156.html

在那里你会找到解决方案(安装 MSys 并在启动 make 时指定参数 -j 以指定数量并行作业)。

一个更简单的解决方案在这里: http://developer.qt.nokia.com/forums /viewthread/855/
(在 QtCreator Tools->Options 中指定 Jom 作为构建工具而不是 NMake)

Visual Studio can compile several projects in parallel, but each single project is compiled sequentially.
So if you compile a solution with 2 projects then two processes will be launched in parallel, but if you have just one project then just one process will start and it will compile your source sequentially.

If you use MingW, you can follow this thread: http://www.mail-archive.com/[email protected]/msg00156.html

There you will find the solution (install MSys and specify the parameter -j when you launch make in order to specify the number of parallel jobs).

An even easier solution is here: http://developer.qt.nokia.com/forums/viewthread/855/
(in QtCreator Tools->Options specify Jom as build tool instead of NMake)

半﹌身腐败 2024-12-16 15:35:18

我也有同样的问题。我们的计算机上正在运行一个软件,该软件试图确定与 Windows 7 的兼容性。该软件会将软件的每次启动记录到数据库中,从而稍微减慢了新进程的启动速度。由于编译器为每个文件启动一个新进程,这显着减慢了整个编译运行的速度。

I had the same problem. On our machines was a software running that tried to determine the compatibility with Windows 7. This software was logging every start of a software to a database and thereby slowed down the startup of new processes a bit. Since the compiler starts a new process for every file this significantly slowed down the whole compile run.

奢欲 2024-12-16 15:35:18

在 Visual Studio 中,您是否转到:

项目 ->属性-> C++ 并将“多处理器编译”改为“是”?这对我打开多核起到了作用,实际上应该可以大大加快速度。

In Visual Studio did you go to:

Project -> Properties -> C++ and turned "Multiprocessor Compilation" to Yes ? That did the Trick for me turning on Multicore, which should speed it up actually quite much.

桃扇骨 2024-12-16 15:35:18

我认为最好的方法是将您的项目拆分为多个项目,每个项目都是静态库项目,通过容器项目(通常是 MainWindow 类)将它们连接在一起。因此,第一次编译需要一段时间,然后就会很短(取决于您的修改)。

I think is best way by splitting your project into multi-projects each project is Static library project join them together by container project which is usually MainWindow class. Thus compiling duration will takes a while for first time then it will be short (depending on your modifications).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文