libtool is adding "-L/usr/lib" even for cross-compilation with sysroot

Xi Ruoyao <[email protected]>
Newsgroups gmane.comp.gnu.libtool.general
Message-ID <[email protected]>
Hi libtool dev,

We've recently hit an issue cross-compiling some package using libtool
for sysroot.  Saying libfoo.la contains

libdir=/usr/lib

Then libtool will add "-L/usr/lib" to the linker command line during a
"relink" against libfoo.la, because ltmain.in:6500:

> 	    else
> 	      # We cannot seem to hardcode it, guess we'll fake it.
> 	      add_dir=-L$libdir
                      ^^^^^^^^^
> 	      # Try looking first in the location we're being installed to.
> 	      if test -n "$inst_prefix_dir"; then
> 		case $libdir in
> 		  [\\/]*)
> 		    func_append add_dir " -L$inst_prefix_dir$libdir"
> 		    ;;
> 		esac
> 	      fi
> 	      add=-l$name
> 	    fi

Now the linker will try to use the system library in /usr/lib, causing
link error or runtime issue.

There is a patch at
https://lists.gnu.org/archive/html/libtool-patches/2021-10/msg00017.html
changing -L$libdir to -L$lt_sysroot$libdir at this line, but maybe the
author didn't submitted it properly (I guess it should be submitted into
https://savannah.gnu.org/patch/?group=libtool, instead of the list). 
Could this change, or something similar be applied in the incoming new
release?
-- 
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.