3

I am building a dll using MSys and Mingw on windows. The source for project only provides a autogen.sh, configure.ac and makefile.am. To generate the makefiles, you run autogen.sh then ./configure. I then go and manually add -no-undefined to the LDFLAGS in the makefile. This is not ideal, during the generation of the makefiles, this LDFLAGS should be set correctly.

Somewhere I have to change a configuration file, so that when the makefiles is generated the LDFLAGS is correctly set.

How do I do that?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Theuns Heydenrych
  • 449
  • 1
  • 4
  • 12

2 Answers2

4

You should be able to set it in Makefile.am. If your library declaration looked something like this:

lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = foo.c

You'd add this line:

libfoo_la_LDFLAGS = -no-undefined
Jack Kelly
  • 18,264
  • 2
  • 56
  • 81
  • This isn't ideal IMO, because it adds it for windows and for linux, doesn't it? Only on windows, one needs this, so I would have expected that it should be done differently! – Johannes Schaub - litb Oct 16 '19 at 20:08
3

As an alternative to Jack Kelly's answer, you can define AM_LDFLAGS in the applicable Makefile.am like,

AM_LDFLAGS = -no-undefined

to pass the flag to the linker for all of your library rules (if so desired, to avoid repetition).


Note that the Autom4ke manual states that,

In some situations, this is not used, in preference to the per-executable (or per-library) _LDFLAGS.

The wording here is not terribly clear, however, the section on libtool flags states,

If ‘library_LIBTOOLFLAGS’ is not defined, then the variable AM_LIBTOOLFLAGS is used instead.

Clearly stated by Calcote in his Autotools,

The existence of a per-product variable overrides Automake's use of the per-makefile variable, so you need to add the per-makefile variable to the per-product variable in order to have the per-makefile variable affect that product [...].

This statement is accompanied by the example,

AM_CFLAGS = ... some flags ...
...
prog1_CFLAGS = ... more flags ... $(AM_CFLAGS)
...
JDQ
  • 443
  • 7
  • 11