如何降低GCC和make的编译成本?
我正在尝试构建一些大型库,例如 Boost 和 OpenCV,来自其源代码 make 和 GCC在我的笔记本电脑上的 Ubuntu 8.10 下。不幸的是,这些大库的编译似乎对我的笔记本电脑来说是很大的负担(Acer Aspire 5000) 。它的风扇发出越来越大的噪音,直到我的笔记本电脑突然自行关闭,而操作系统却没有正常关闭。
所以我想知道在make和GCC的情况下如何降低编译成本?
我不介意编译是否需要更长的时间或更多的空间,只要它可以在我的笔记本电脑不自行关闭的情况下完成即可。
由于没有优化,构建调试版本的库是否总是比构建发布版本的成本更低?
一般来说,是否可以只指定要安装的库的某些部分而不是完整的库?如果以后发现需要的话,其余的可以构建和添加吗?
如果我重新启动笔记本电脑,我可以从笔记本电脑自行关闭时的位置恢复编译,这是否正确?例如,通过查看编译期间显示的进度百分比,我发现 OpenCV 确实如此,不会从 0% 重新启动。但我对 Boost 不太确定,因为没有明显的信息可以告诉我,而且编译似乎需要更长的时间。
更新:
谢谢 brianegge 和 Levy Chen!如何使用 GCC 和/或 g++ 的包装脚本?这就像为 GCC 或 g++ 定义一些别名吗?如何调用脚本来检查传感器并等到CPU温度下降后再继续?
I am trying to build some big libraries, like Boost and OpenCV, from their source code via make and GCC under Ubuntu 8.10 on my laptop. Unfortunately the compilation of those big libraries seem to be big burden to my laptop (Acer Aspire 5000). Its fan makes higher and higher noises until out of a sudden my laptop shuts itself down without the OS gracefully turning off.
So I wonder how to reduce the compilation cost in case of make and GCC?
I wouldn't mind if the compilation will take much longer time or more space, as long as it can finish without my laptop shutting itself down.
Is building the debug version of libraries always less costly than building release version because there is no optimization?
Generally speaking, is it possible to just specify some part of a library to install instead of the full library? Can the rest be built and added into if later found needed?
Is it correct that if I restart my laptop, I can resume compilation from around where it was when my laptop shut itself down? For example, I noticed that it is true for OpenCV by looking at the progress percentage shown during its compilation does not restart from 0%. But I am not sure about Boost, since there is no obvious information for me to tell and the compilation seems to take much longer.
UPDATE:
Thanks, brianegge and Levy Chen! How to use the wrapper script for GCC and/or g++? Is it like defining some alias to GCC or g++? How to call a script to check sensors and wait until the CPU temperature drops before continuing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议为 gcc 和/或 g++ 创建一个包装脚本
将上面的内容保存为“gccslow”或其他内容,然后:
或者,您可以调用脚本 gcc 并将其放在您的脚本前面小路。如果这样做,请确保在脚本中包含完整路径,否则脚本将递归调用自身。
更好的实现可以调用脚本来检查传感器并等到 CPU 温度下降后再继续。
I'd suggest creating a wrapper script for gcc and/or g++
Save the above as "gccslow" or something, and then:
Alternatively, you can call the script gcc and put it at the front of your path. If you do that, be sure to include the full path in the script, otherwise, the script will call itself recursively.
A better implementation could call a script to check sensors and wait until the CPU temperature drops before continuing.
对于后一个问题:编写良好的 Makefile 会将依赖关系定义为 有向非循环图 (DAG),它将尝试通过按照 DAG 的顺序编译它们来满足这些依赖关系。因此,当编译文件时,依赖性就得到满足,不需要再次编译。
然而,编写好的 Makefile 可能会很棘手,因此有时作者会求助于蛮力方法,并从头开始重新编译所有内容。
对于您的问题,对于此类众所周知的库,我将假设 Makefile 已正确编写,并且构建应从上次操作恢复(需要注意的是,它需要重新扫描 DAG,并重新计算编译顺序,这应该是相对便宜)。
For your latter question: A well written Makefile will define dependencies as a directed a-cyclical graph (DAG), and it will try to satisfy those dependencies by compiling them in the order according to the DAG. Thus as a file is compiled, the dependency is satisfied and need not be compiled again.
It can, however, be tricky to write good Makefiles, and thus sometime the author will resort to a brute force approach, and recompile everything from scratch.
For your question, for such well known libraries, I will assume the Makefile is written properly, and that the build should resume from the last operation (with the caveat that it needs to rescan the DAG, and recalculate the compilation order, that should be relatively cheap).
您可以单独编译每个目标,而不是编译整个目标。您必须检查
Makefile
来识别它们。半开玩笑:编译时把笔记本电脑放进冰箱怎么样?
Instead of compiling the whole thing, you can compile each target separately. You have to examine the
Makefile
for identifying them.Tongue-in-cheek: What about putting the laptop into the fridge while compiling?