automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to create optimized library?


From: Benoit SIGOURE
Subject: Re: How to create optimized library?
Date: Tue, 30 Oct 2007 08:49:35 +0100

On Oct 29, 2007, at 11:09 PM, address@hidden wrote:

Hi,

Hi,

I want to create some optimized library from .c and .cc files. I created AM_CPPFLAGS in Makefile.am, but the code is always compiled with '- g -O2' flags. I defined 'CPPFLAGS' in the configure, it still does not work. Do
you know how to create optimized library?

CPPFLAGS = C PreProcessor flags, they have nothing to do with compilation optimization flags. You must use AM_CFLAGS / AM_CXXFLAGS for this. But this won't solve your problem anyways. There are (mainly) two layers of flags: the flags of the maintainer (e.g., AM_CFLAGS) and the flags of the user (e.g., CFLAGS). Since "the user is always right", the user flags (e.g., CFLAGS) always come after that of the maintainer, so that he can override everything. So even if you do something like AM_CFLAGS = -O3 -fmy-optimization-of- death, the user can always do ./configure CFLAGS='-O0 -fno-my- optimization-of-death' and the resulting invocation of GCC will be `gcc -O3 -fmy-optimization-of-death -O0 -fno-my-optimization-of- death ...' and no optimization will be performed.

The reason why you see '-g -O2' is that, by default, when the user doesn't specify any flag and when the compiler is GCC, autoconf will put '-g -O2' in CFLAGS. You, as a maintainer, should really avoid to put your hands in the user's reserved variables (such as CFLAGS) but if you really truly need to override CFLAGS for default builds, you should do something along the lines of CFLAGS="$CFLAGS -my-flag".

I'd recommend to not do this and instead invoke ./configure CFLAGS="- what-you-want-here".

Another question: what is the name format of optimized library, will the file name include '-O' in the end? Or should I define it myself? Thanks.

Optimized library should not need to have a special name. The only reason I'd see where one would want to name the library differently is when you use compiler flags that change the ABI of the code produced. If you happen to do this for some reason, then just name the library the way you want, there is no standard naming convention that I am aware of. Some people tend to produce up to 4 libraries per library (one compiled normally with standard optimizations, one compiled with debugging symbols and suffixed by `-d', one compiled with multi-threading support and suffixed by `-mt', and one compiled with debugging+multi-threading and suffixed by `-mt-d', AFAIR Boost does this).

The automake manual[1] explains how to build different targets differently but from the same sources. I think you'll need this if you want to build your libraries twice with different CFLAGS/CXXFLAGS.

[1] http://www.gnu.org/software/automake/manual/html_node/true.html

Cheers,

--
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory


Attachment: PGP.sig
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]