Subject: bug#78072: Libtool incorrectly tries to use shared library when linking statically

From: Ileana Dumitrescu <[email-masked]>
Date: Tue, 29 Apr 2025 16:58:52 +0300

On 28/04/2025 18:47, Mike Krinkin wrote:
> Hi Ileana,
> 
> thank you for the response. I will try to test it out to confirm if your 
> suggestions will fix the issue, it would take some time though.
> 
> The problem in our case though is that colm for us is a dependency - 
> it's not a project we own.
> So while I can apply changes you suggested to test if they work, that's 
> not a solution we will be able to settle on.
> 
> Is there any reason why --static flag that was provided to libtool is 
> not enough indication to libtool to pick a static library over a shared 
> one when both are available?

I thought it should be enough indication, but after looking through
ltmain.in, the --static flag does not seem to be used for configuring
other variables that libtool needs, like prefer_static_libs:

	# Get the name of the library we link against.
	linklib=
	if test -n "$old_library" &&
	   { test yes = "$prefer_static_libs" ||
	     test built,no = "$prefer_static_libs,$installed"; }; then
	  linklib=$old_library
	else
	  for l in $old_library $library_names; do
	    linklib=$l
	  done
	fi

I have not been able to reproduce this issue easily, so I am not sure if
the following patch will work:

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index aaf48f14..11cf1c44 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -4848,7 +4848,7 @@ func_mode_link ()
  	build_old_libs=no
  	break
  	;;
-      -all-static | -static | -static-libtool-libs)
+      -all-static | -static | -static-libtool-libs | --static | -Bstatic)
  	case $arg in
  	-all-static)
  	  if test yes = "$build_libtool_libs" && test -z "$link_static_flag"; 
then
@@ -4865,7 +4865,7 @@ func_mode_link ()
  	  fi
  	  prefer_static_libs=built
  	  ;;
-	-static-libtool-libs)
+	-static-libtool-libs | --static | -Bstatic)
  	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
  	    dlopen_self=$dlopen_self_static
  	  fi

If prefer_static_libs is already set to yes in your build, the above
patch should have no effect.

-- 
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354