bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: linking with libguile-2.0, rpath


From: Bruno Haible
Subject: Re: linking with libguile-2.0, rpath
Date: Sat, 19 Feb 2011 16:30:15 +0100
User-agent: KMail/1.9.9

Hi Andy,

> > $ gcc -o simple-guile simple-guile.c  `pkg-config --cflags --libs guile-2.0`
> > $ ./simple-guile 
> > ./simple-guile: error while loading shared libraries: libguile-2.0.so.22: 
> > cannot open shared object file: No such file or directory
> 
> Bruno Haible first brought up the issues here:
> 
>   http://lists.gnu.org/archive/html/libtool/2001-11/msg00050.html
> 
> I don't know of a consensus for the solution, so I'm copying him on the
> mail here.

A lot of progress has been made on this since 2001. You now find in gnulib
a module 'havelib', consisting essentially of a file lib-link.m4 and a file
config.rpath, that determine the appropriate flags for encoding the rpath
(runtime search path) in an executable or shared library.

> Bruno, what should we recommend in the manual that users do 
> to link to Guile, and produce an executable that correctly finds
> libguile when it is run?

First of all, the macro GUILE_FLAGS in guile.m4 needs to be extended.
Find attached a patch that does 3 things:
  - Fix the documentation of GUILE_CFLAGS to mention that it may contain
    several -I options. (It did for me, because I had bdw-gc installed at
    a different location than guile.)
  - Fix the documentation of GUILE_LDFLAGS to mention that it contains
    flags for the compiler, not for the linker (you use it with $CC, not
    with 'ld'), that it may contain several -L options (as it did for me),
    and that it is usually insufficient for producing working programs.
  - Define variables GUILE_LIBS and GUILE_LTLIBS that can be used instead
    of GUILE_LDFLAGS and that produce working programs. One is for use
    with the compiler, the other one for use with libtool. (GUILE_LDFLAGS
    contains options like -Wl,-rpath that libtool would not understand,
    and GUILE_LTLIBS contains options like -R that the compiler would not
    understand.)

For example, I put these lines into a configure.ac

  GUILE_FLAGS
  echo "GUILE_LIBS = $GUILE_LIBS"
  echo "GUILE_LTLIBS = $GUILE_LTLIBS"

and got this output, as expected:

checking libguile compile flags... -Wall -pthread 
-I/arch/x86_64-linux/gnu-inst-guile/2.0.0/include/guile/2.0 
-I/arch/x86_64-linux/gnu-inst-libunistring/0.9.3/include 
-I/arch/x86_64-linux/gnu/include  
checking libguile link flags... -L/arch/x86_64-linux/gnu-inst-guile/2.0.0/lib64 
-L/arch/x86_64-linux/gnu/lib64 -lguile-2.0 -lgc  
GUILE_LIBS = -L/arch/x86_64-linux/gnu-inst-guile/2.0.0/lib64 
-L/arch/x86_64-linux/gnu/lib64 -lguile-2.0 -lgc   -Wl,-rpath 
-Wl,/arch/x86_64-linux/gnu-inst-guile/2.0.0/lib64 -Wl,-rpath 
-Wl,/arch/x86_64-linux/gnu/lib64
GUILE_LTLIBS = -L/arch/x86_64-linux/gnu-inst-guile/2.0.0/lib64 
-L/arch/x86_64-linux/gnu/lib64 -lguile-2.0 -lgc   
-R/arch/x86_64-linux/gnu-inst-guile/2.0.0/lib64 -R/arch/x86_64-linux/gnu/lib64

Second, about the documentation. A command line

  $ gcc -o simple-guile simple-guile.c  `pkg-config --cflags --libs guile-2.0`

cannot work in general, because the list of directories to use in the -rpath
option(s) comes from pkg-config, but it needs to be presented in a syntax that
depends on the compiler (think of Solaris, where the option for gcc is
-Wl,-rpath and the option for cc is -R), and pkg-config does not know about the
compiler.

That's also the reason why I propose to add this logic to the GUILE_FLAGS macro
and not to the 'guile-config' program.

So, for the documentation, I only see an ad-hoc approach:

# Define a function that transform -L options to rpath options. This definition
# works with gcc on glibc systems. On other platforms, the details are 
different.
$ transform_L_options_to_rpath_options ()
{
  sed -e 's/^/ /' | sed -e 's/ -l *[^ ]*//g' -e 's/ -L */ -Wl,-rpath -Wl,/g'
}

With this, the command line becomes

$ gcc -o simple-guile simple-guile.c
      `pkg-config --cflags --libs guile-2.0`
      `pkg-config --libs guile-2.0 | transform_L_options_to_rpath_options`

or with the use of guile-config:

$ gcc -o simple-guile simple-guile.c \
      `guile-config compile` \
      `guile-config link` \
      `guile-config link | transform_L_options_to_rpath_options`

Bruno

-- 
In memoriam Friedrich Weißler <http://en.wikipedia.org/wiki/Friedrich_Weißler>

Attachment: guile.m4.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]