[comp.windows.x] LD_LIBRARY_PATH woes

sysnmc@magic706.chron.COM (Matt Cohen) (05/26/90)

uunet!ssi!ssiwest!quenelle (Chris Quenelle) says:

> > Execute "ldd xdvi" to see what libraries the dynamic linker expects to find.
> > I suspect during the ld step, an R3 version of libX11 is getting used
> > instead of the R4 version. We've had this problem when we set
> > LD_LIBRARY_PATH and it includes the OpenWindows directories.
> 
> I thought I'd post my solution to this.
> Whenever I compile an X program, I'm always sure to unset LD_LIBRARY_PATH.
> (This means you have to get the -L option right)
> This has the disadvantage of making the binary less portable,
> (the libraries have to be in the same place), but it has the advantage
> of making that binary immune to the LD_LIBRARY_PATH variable at run-time.

	In general, you shouldn't need LD_LIBRARY_PATH at all.

	It looks like your setup is similar to mine, and many
other people's: you run X11R4 most of the time, and OpenWindows sometimes.

	Just copy the OpenWindows dynamic libraries into /usr/lib and the
dynamic loader takes care of everything. The secret is the loader's use
of major and minor version numbers. The major version of the library that
gets loaded must match the major version the program was compiled with. The
loader uses the highest minor version available. The MIT libraries are 
major version 4, and the OpenWindows libraries are major version 0.

	So when you run a program, everything works fine since
the OpenWindows program were compiled with version 0 libraries and the
MIT programs with version 4. The only possible gotcha is when you want to 
compile a program to use the OpenWindows libraries, you have to use 
(for example) -lX11.0 instead of -lX11.

	In fact, I often use the OpenWindows mailtool while running
MIT X11R4.

	Much thanks to Heather Rose who pointed out much of this in
a posting a while back. Take a look at the manual pages ld(1) and ldd(1).

	Good luck!

			-- Matt

Matt Cohen                              INET: sysnmc@chron.com
Department of Technology Resources      UUCP: ...!uunet!chron!sysnmc
The Houston Chronicle                   AT&T: +1 713 220 7023
801 Texas Avenue, Houston, TX 77002     "The opinions above are most likely
"Houston's Leading Information Source"        those of my employer."

montnaro@spyder.crd.ge.com (Skip Montanaro) (05/30/90)

The problems identified by Chris Quenelle (<9005291632.AA06491@ssiwest.com>)
regarding LD_LIBRARY_PATH are only part of the problem related to multiple
window systems on Suns. At GE CRD users can choose between Suntools, Quest
X11R3, MIT X11R3, MIT X11R4, and Sun's OpenWindows. Some people (like
myself) go back and forth between two or three of them with some regularity.

I've identified the following user-level problems that make it impossible to
establish a single environment at login time that will work for all window
systems I might want to run:

    * LD_LIBRARY_PATH - Its contents change between X11R4 and OpenWindows

    * PATH - For instance:

	The xterm that comes with X11R3 or X11R4 doesn't work well (at all?)
	with OpenWindows.

	In OpenWindows, Sun thoughtfully placed xterm in the OpenWindows
	demos directory, where it resides with several NeWS-dependent
	commands, thus .../demos can't be in your PATH when running anything
	but OpenWindows.

	Several commands have the same name in OpenWindows and Suntools.
	Unfortunately, the Suntools versions reside in /usr/bin, so it's
	impossible (well, a major inconvenience) to eliminate them from
	PATH, and they must be down in the PATH when running X. The X paths
	can't be there when running Suntools, however. 

    * OpenWindows-specific environment variables - At various times over the
      last couple of years various versions of NeWS or OpenWindows have
      required the following environment variables to be defined:
      NEWSSERVER, OPENWINHOME, XNEWSHOME, NEWSHOME. If you count OW GUIDE as
      part of OpenWindows, add GUIDEHOME. Software from other sources (such
      as the Turing Institute's GoodNeWS and HyperNeWS) expect to find other
      environment variables.

    * Beta test software - We've beta-tested some OpenWindows-related
      software for Sun over the past couple of years. Usually the beta test
      and latest released version are only, and you might want to choose one
      or the other at run-time  for various reasons.

Consequently, I gave up several months ago, and just wrote shell scripts to
establish the proper environment for the different window systems. Since
they're short, I've included the two I use for OpenWindows and X11R4. They
don't solve all problems, but reduce them to manageable proportions. They
look somewhat different mostly because I tried for different amounts of
robustness in the two. A few other people use my xnews.sh script.

(For reference, PATH1 lists my private command/binary directories, and PATH2
lists the standard system directories - /usr/bin et al. ARCH is set based
upon machine architecture. All are set at login time.)

For X11R4 (my version of startx):
-------------------------
#!/bin/sh

MITXBIN=/usr/bin/X11
OPENWINHOME=/common/$ARCH/openwin
LD_LIBRARY_PATH=/usr/lib:$OPENWINHOME/lib
MANPATH=$OPENWINHOME/share/man:$MANPATH
GUIDEHOME=$OPENWINHOME
PATH=$PATH1:$MITXBIN:$OPENWINHOME/bin:$OPENWINHOME/bin/xview:\
$OPENWINHOME/demo:$PATH2
DISPLAY=${DISPLAY:-localhost:0}

export OPENWINHOME LD_LIBRARY_PATH MANPATH GUIDEHOME PATH DISPLAY

$MITXBIN/startx "$@"
-------------------------

For OpenWindows (my xnews command):
-------------------------
#!/bin/sh

ARCH=${ARCH:-`arch`}

if ask_yn "Use OpenWindows Beta" ; then
    OPENWINHOME=/home/kreskin/private/users/$ARCH/openwin/beta
else
    OPENWINHOME=/home/kreskin/private/users/$ARCH/openwin
fi

GUIDEHOME=$OPENWINHOME/guide
GNHOME=/home/kreskin/source/public/NeWS/GoodNeWS1.3
HNHOME=/home/kreskin/source/public/NeWS/HyperNeWS1.3

if [ x$LD_LIBRARY_PATH != x ] ; then
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OPENWINHOME/lib
else
    LD_LIBRARY_PATH=$OPENWINHOME/lib
fi

MANPATH=$OPENWINHOME/share/man:$MANPATH

# user's private commands
PATH1=${PATH1:-$HOME/bin/$ARCH:$HOME/bin}

# generic system commands
PATH2=${PATH2:-/common/$ARCH/bin:/usr/ucb:/usr/bin:/usr/etc:/bin:/etc:/usr/5bin:.}

XPATH=$GNHOME/bin-$ARCH-xnews:$HNHOME/bin-$ARCH-xnews:$OPENWINHOME/bin:\
$OPENWINHOME/bin/xview:$GUIDEHOME/bin:$OPENWINHOME/demo:/usr/bin/X11

if [ $PATH = $PATH1:$PATH2 ] ; then
    # stick the windows stuff between the user's private commands and the 
    # generic stuff
    PATH=$PATH1:$XPATH:$PATH2
else
    # user has other stuff in PATH besides PATH1 & PATH2, so just tack XPATH
    # on the front of PATH
    PATH=$XPATH:$PATH
fi

DISPLAY=${DISPLAY:-localhost:0}
NEWSSERVER=${NEWSSERVER:-`newsserverstr localhost`}

export	OPENWINHOME XNEWSHOME LD_LIBRARY_PATH MANPATH GUIDEHOME PATH \
	DISPLAY NEWSSERVER GNHOME HNHOME

$OPENWINHOME/bin/xnews > /tmp/NeWStrace 2>&1
-------------------------
--
Skip (montanaro@crdgw1.ge.com)