Bug 16183 - LDFLAGS overrides PKG_LIBS
Summary: LDFLAGS overrides PKG_LIBS
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Installation (show other bugs)
Version: R-devel (trunk)
Hardware: Other Other
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-02-02 18:31 UTC by Poor Yorick
Modified: 2015-02-02 18:31 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Poor Yorick 2015-02-02 18:31:47 UTC
"Writing R Extension" says, "...variable PKG_LIBS in Makevars can be used for
additional ‘ -l ’ and ‘ -L ’ flags to be passed to the linker when building the
shared object."  It doesn't say that those flags override what is provided by R
via etc/Makeconf/$LDFLAGS, and indeed they do not, as share/make/shlib.mk
places $(ALL_LIBS) after $(SHLIB_LINK), which contains $(LDFLAGS).  This means
that packages that provide an option like --with-needed-library=xxx, and then
add the corresponding -L and -l flags to $(PKG_LIBS), may end up linking to an
unexpected shared object in some path specified by $(LDFLAGS), whose "-L" flags
override those of $(PKG_LIBS).

One fix, although perhaps a bit hacky, is the following modification:


    --- R-3.0.2/etc/Makeconf.in   2013-08-26 18:05:05.000000000 -0400
    +++ R-3.0.2.new/etc/Makeconf.in  2015-02-01 20:28:40.000321000 -0500
    @@ -89,7 +89,7 @@
     SHLIB_LD = @SHLIB_LD@
     SHLIB_LDFLAGS = @SHLIB_LDFLAGS@@BUILD_LTO_TRUE@ $(CFLAGS) $(CPICFLAGS)
     SHLIB_LIBADD = @SHLIB_LIBADD@
    -SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LDFLAGS)
    +SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(ALL_LIBS) $(LDFLAGS)
     SHLIB_OPENMP_CFLAGS = @SHLIB_OPENMP_CFLAGS@
     SHLIB_OPENMP_CXXFLAGS = @SHLIB_OPENMP_CXXFLAGS@
     SHLIB_OPENMP_FCFLAGS = @SHLIB_OPENMP_FCFLAGS@


This results in $(ALL_LIBS) being included twice, both before and after
$(LDFLAGS).  The duplication of $(ALL_LIBS), however distasteful, does have the
desirable effect of placing package-specifig -L flags toward the start of the
command line while placing "-l" flags toward the end.