Subject: library inclusion order bug with pkgsrc
To: None <>
From: Georg Schwarz <>
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/ undefined reference to
/usr/local/pkg/lib/ undefined reference to
/usr/local/pkg/lib/ undefined reference to
/usr/local/pkg/lib/ undefined reference to
/usr/local/pkg/lib/ undefined reference to
/usr/local/pkg/lib/ undefined reference to
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

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/      Thu Apr 14 00:42:41 2005
+++ mk/   Thu Apr 14 01:16:23 2005
@@ -187,7 +187,8 @@
 .if defined(USE_X11)
 X11_LDFLAGS+=          -L${X11BASE}/lib${LIBABISUFFIX}
-LDFLAGS+=              ${X11_LDFLAGS}
+                       -L${LOCALBASE}/lib ${X11_LDFLAGS}

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.


Georg Schwarz     +49 178 8545053