Subject: library inclusion order bug with pkgsrc
To: None <tech-pkg@netbsd.org>
From: Georg Schwarz <georg.schwarz@freenet.de>
List: tech-pkg
Date: 04/14/2005 01:47:34
There is a problem with the library inclusion order induced by pkgsrc.
On my Linux system there is a native Xrender libary in /usr/X11R6/lib,
which is not exchanchable with the pkgsrc one installed of course under
${LOCALBASE}/lib (/usr/local/pkg/lib here). pkgsrc should of course only
use the latter one.
However, when compiling packages like x11/gtk2 or net/kphone, the following
problem occurs (excerpt from config.log): 

...
 gcc  -Wl,-R/usr/X11R6/lib -L/usr/local/pkg/lib /var/tmp/test.c
-Wl,-R/usr/local/pkg/lib  -lpangoxft-1.0
/usr/local/pkg/lib/libpangoxft-1.0.so: undefined reference to
`XRenderFindStandardFormat'
/usr/local/pkg/lib/libXft.so.2: undefined reference to
`XRenderCompositeText32'
/usr/local/pkg/lib/libXft.so.2: undefined reference to
`XRenderCompositeText16'
/usr/local/pkg/lib/libXft.so.2: undefined reference to
`XRenderQuerySubpixelOrder'
/usr/local/pkg/lib/libpangoxft-1.0.so: undefined reference to
`XRenderCompositeTrapezoids'
/usr/local/pkg/lib/libXft.so.2: undefined reference to
`XRenderCompositeText8'
collect2: ld returned 1 exit status

In the same file one sees

ac_cv_env_LDFLAGS_value=' -Wl,-R/usr/X11R6/lib -L/usr/X11R6/lib
-L/usr/local/pkg /lib -Wl,-R/usr/local/pkg/lib -L/usr/lib -Wl,-R/usr/lib
-pthread'

And indeed PKG_DEBUG_LEVEL=1 confirms this:

LDFLAGS= -Wl,-R/usr/X11R6/lib -L/usr/X11R6/lib -L/usr/local/pkg/lib
-Wl,-R/usr/local/pkg/lib -L/usr/lib -Wl,-R/usr/lib -pthread

(Strangely, /usr/local/pkg/bin/bmake show-vars VARNAMES=LDFLAGS
only shows -Wl,-R/usr/X11R6/lib -L/usr/X11R6/lib
Anbyone knows why?)

Now since -Wl,-R/usr/X11R6/lib -L/usr/X11R6/lib is first the system X11
libraries are preferred over the pkgsrc ones, which can lead to
incompatibilities as in the above case.

I used the following patch to pkgsrc to work around the issue:

--- mk/bsd.pkg.use.mk.orig      Thu Apr 14 00:42:41 2005
+++ mk/bsd.pkg.use.mk   Thu Apr 14 01:16:23 2005
@@ -187,7 +187,8 @@
 .if defined(USE_X11)
 X11_LDFLAGS+=          ${COMPILER_RPATH_FLAG}${X11BASE}/lib${LIBABISUFFIX}
 X11_LDFLAGS+=          -L${X11BASE}/lib${LIBABISUFFIX}
-LDFLAGS+=              ${X11_LDFLAGS}
+LDFLAGS+=              ${COMPILER_RPATH_FLAG}${LOCALBASE}/lib \
+                       -L${LOCALBASE}/lib ${X11_LDFLAGS}
 .endif
 
 ### USE_XPKGWEDGE

This of course won't help if the correct libs happen to be placed in a
subdirectory. I am not sure if such a scenario could occur.

The alternative would be to add X11_LDFLAGS to LDFLAGS only at a later
state, but since it is unclear to me where the remaining package-induced
flags are added I do not know how to accomplish that.

The problem should occur on any system where native X11 libaries have the
same names as pkgsrc ones with which they not happen to be interchangable
(this makes it clear why this problem will never surface on NetBSD).

I would very much appreciate feedback on that issue.

Thanks.

Georg
  
-- 
Georg Schwarz    http://home.pages.de/~schwarz/
 georg.schwarz@freenet.de     +49 178 8545053