On 2021-01-14 02:45, Sébastien Hinderer wrote:
Dear autoconf and make users,
I suspect mailing list cross-posting doesn't work well in an
age in which mailing lists don't accept postings from non-subscribers
due to the spam problem.
Your question reaches people who are subscribed only to one
of the lists, and can only post to that one.
The status of the LIBS and LDLIBS variables is unclear to me.
Do both of them have a conventional meanings, or are they just
alternatives for the same thing, namely giving libraries that should be
passed to the ld linker?
./configure --help refers to LIBS but in make's manual it's LDLIBS
which
is mentionned and the GNU coding standard at
https://www.gnu.org/prep/standards/html_node/index.html does not
help...
The GNU make manual is clear about this:
'LDFLAGS'
Extra flags to give to compilers when they are supposed to invoke
the linker, 'ld', such as '-L'. Libraries ('-lfoo') should be
added to the 'LDLIBS' variable instead.
'LDLIBS'
Library flags or names given to compilers when they are supposed to
invoke the linker, 'ld'. 'LOADLIBES' is a deprecated (but still
supported) alternative to 'LDLIBS'. Non-library linker flags, such
as '-L', should go in the 'LDFLAGS' variable.
The built-in rules for linking reference these variables. If your
program uses the built-in rules, then it doesn't have to do anything
in order to support these variables.
If you write your own linking recipe from scratch, it should mimic
the built-in one and refer to LDFLAGS and LDLIBS.
The main idea is that these variables (along with CFLAGS and some
others)
belong to the user who builds the program, who may need to use them
to pass additional compiler options.
This means that your build system reacts and incorporates the values
of these variables if they are set in the environment or on the make
command line, but does not set them itself.
Use your own variables to specify everything that is internally
necessary for your program to build and work.
Do not do the following:
CFLAGS = -std=c99 -D_POSIX_SOURCE -O2 # program's needed flags
LDLIBS = -lfoo -lbar # program's needed libs
The problem is that if the user wants to add some extra flag,
they have to replicate all of your required flags that are specific
to your program.
These variables are typically globally set by operating system distro
builds. Programs which hijack the variables for specifying necessary
options and libraries cause work for package and distro maintainers.
For instance, a distro might use CFLAGS to select a consistent ABI
across the entire system, or to select code generation for a
a particular instruction set. Or LDLIBS to inject some common
library into every program. I suspect that is rare, but distro-wide
use of LDFLAGS is very common.
I see I'm missing support for LDLIBS in some of my programs,
but I've not received any reports about this.
LIBS does appear in the GNU Make manual, in a 1991-dated
"complex Makefile example" from GNU tar which doesn't reflect current
good practices.