Tuesday, December 19, 2006

C/C++ parameters at configure time

If you ever compiled an open source program from sources, you'll surely know the sequence:

./configure
make
make install

In particular, the first command will try to figure out the system you're using for compilation and to set some parameters accordingly (C and C++ compiler, missing features, etc.). This script is usually automatically built using the GNU Autotools, such as autoconf, automake, libtool.

The configure usually assume the following parameters for the C/C++ compiler:

-g -O2

That is, enable debugger information, and perform optimizations and for the end user this might be OK.

However, for the developer, who probably will have to debug the program, having the optimizations enabled might make debugging a nightmare (since some instructions might be rearranged by the optimizer). For this reason, I usually disable optimizations at configuration time simply by using the following configure command line:

./configure CXXFLAGS="-g" CFLAGS="-g"

So that debugging will be much easier!

No comments: