[Top][All Lists]

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

Re: C flags and headers in a C library

From: Noah Misch
Subject: Re: C flags and headers in a C library
Date: Thu, 3 May 2007 11:09:47 -0700
User-agent: Mutt/1.5.9i

On Thu, May 03, 2007 at 01:02:49PM +0100, Joseph Wakeling wrote:
> Noah Misch wrote:

> >   AM_CFLAGS = -ansi -pedantic -Wall
> > 
> > Note that it's usually unwise to add such flags unconditionally; many 
> > compilers
> > do not support them.
> Thanks very much.  I hadn't thought about the compiler issue; can you
> suggest a conditional check that would sort this out?

You can do something like this:

This is reasonable for `-Wall', but I don't recommend it for `-ansi' or
`-pedantic', since the compiler may accept the option but then reject your code
due to a pedantic language check.  While useful for development, that does not
aid those who simply want to build and use your library.

> Alternatively, is there some way I can just request the extra flags when
> calling autoreconf or the ./configure script?  After all, it's only
> really necessary for me, as the code author, to check ANSI compatibility.

You can just `./configure CFLAGS='-g -O2 -ansi -pedantic -Wall' for your own

> A last query.  When building a library, is it advisable to link to other
> libraries when compiling?  e.g. if my library uses functions from
> libmath, should I compile my library with -lm, or leave that to the
> person creating executables linked with my library?

You should link your own library to its dependencies.  This is essential when
building on systems that forbid undefined symbols in libraries.  Furthermore,
when others use Libtool to link with your library, Libtool will link in those
dependencies automatically.

reply via email to

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