Sara
Sara

Reputation: 86

what is the difference between AM_LDFLAGS and LDFLAGS

I want to know what is the difference between AM_LDFLAGS and LDFLAGS, as I've faced an error

error: AM_LDFLAGS must be set with '=' before using '+='

while I was using AM_LDFLAGS in a foreach loop my make file code is as shown below:

program_INCLUDE_DIRS := /usr/bin/PR__bin

program_LIBRARY_DIRS := /usr/lib/PR__lib

CFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))

AM_LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))

Upvotes: 3

Views: 5056

Answers (2)

Sourav Ghosh
Sourav Ghosh

Reputation: 134326

_I want to know what is the difference between AM_LDFLAGS and LDFLAGS_

LDFLAGS is the variable inherited from Autoconf, AM_LDFLAGS is a variable defined by automake.

As per the automake manual page,

This is the variable the Makefile.am author can use to pass in additional linker flags. In some situations, this is not used, in preference to the per-executable (or per-library) _LDFLAGS.

However, reagrding the error, as per the information provided here, it looks like a problem on the usage of the variable. Automake expects that the variable must be set to some value before it can be appended.

The correct way to solve this would be same as the one mentioned in the other answer provided by Etan Reisner, simply set the AM_LDFLAGS explicitly before the loop, something like

AM_LDFLAGS =     // which "sets" the AM_LDFLAGS

and then do

AM_LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))

Upvotes: 5

Etan Reisner
Etan Reisner

Reputation: 80931

If that error is complaining about what it says it is complaining about (and I'm not at all sure why it would/should be) then I would think the solution would be as simple as just adding

AM_LDFLAGS =

as the line above the foreach loop that uses +=.

From section 8.7 Variables used when building a program of the GNU Automake manual:

AM_LDFLAGS

This is the variable the Makefile.am author can use to pass in additional linker flags. In some situations, this is not used, in preference to the per-executable (or per-library) _LDFLAGS.

Upvotes: 1

Related Questions