This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: exes can't find libstdc++.so without help


Perhaps this can be put in the FAQ?

When gcc-3.0 is installed in a non-standard prefix (not /usr or /usr/local etc),
for instance as second compiler, then C++ programs can have a hard time finding
the correct libstdc++ when being run.

This can be solved easily by including the path to libstdc++ (and other compiler
version specific libraries) in the executable itself.  A disadvantage is that this
will only work on the same machine as where the executable was build, but that is
normally not a problem for executables that are build with a "second" compiler (not
the default compiler of the OS).

I wrote a script (it works with bash) that provides a proxy for an arbitrary
number of installed compilers (gcc and g++).  The script assumes that the
prefix used for each compiler is the same, except for the version number
that must be included in the prefix.  For example, for version 3.0 use
--prefix=/usr/local/gcc-3.0, and for version 2.95.2 use --prefix=/usr/local/gcc-2.95.2.

Put the following script in your PATH and call it [gcc|g++]-[2.95.2|3.0], make a
hardlink for every version (one for gcc and one for g++, for example: gcc-2.95.2,
g++-2.95.2, gcc-3.0, g++-3.0 etc).  Correct the PREFIX variable in the script.

-------<< start -------------------------------------------
COMPILER_VERSION=`echo $0 | sed -e 's%^.*-\(.*\)%\1%'`
PREFIX=/usr/local/gcc-$COMPILER_VERSION
COMPILER=`echo $0 | sed -e 's%^.*/\(...\)[^/]*%\1%'`
if [ $# = 1 -a $1 = '-v' ]; then
  $PREFIX/bin/$COMPILER -v
  exit 0
fi
(
  (
    if $PREFIX/bin/$COMPILER "-Wl,-rpath,$PREFIX/lib:$LD_RUN_PATH" $*; then
      echo 'compilation successful' >&4
    fi 2>&1 1>&3 | grep -v ' linking not done' 1>&2
  ) 4>/dev/null 4>&1 | grep 'compilation successful' >/dev/null
) 3>/dev/null 3>&1
-------<< end ---------------------------------------------

The fiddling with the filedescriptors and `grep' is needed to preserve the
correct exit value.

-- 
Carlo Wood <carlo@alinoe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]