tags:

views:

121

answers:

3

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?

+4  A: 

I'd suggest creating a wrapper script for gcc and/or g++

#!/bin/bash
sleep 10
exec gcc "$@"

Save the above as "gccslow" or something, and then:

export CC="gccslow"

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.

brianegge
That is a clever solution. Initially, I was pondering the use of `nice`, but it wouldn't have helped, because the CPU would have been kept busy anyway.
Chen Levy
Thanks, brianegge! How do you 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?
Tim
+2  A: 

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).

Chen Levy
Boost uses its own mechanism (bjam).
MSalters
+1  A: 

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?

mouviciel