On Fri, Apr 12, 2002 at 01:10:19PM +0400, Dmitry Mottl wrote:
> Hi,
> sorry, for possible offtopic, but freebsd-question said nothing
> 
> How can I link C program with different versions of the same library?
> 
> # /sbin/ldconfig -r | grep ncurses
>     5:-lncurses.5 => /usr/lib/libncurses.so.5
>     84:-lncurses.3 => /usr/lib/compat/libncurses.so.3
> # gcc test.c -lncurses
> # ldd a.out
> a.out:
>     libncurses.so.5 => /usr/lib/libncurses.so.5 (0x28065000)
>     libc.so.4 => /usr/lib/libc.so.4 (0x280a7000)
> 
> 
> But if I explicitly set version of library:
> # gcc test.c -lncurses.5
> /usr/libexec/elf/ld: cannot find -lncurses.5
> 
> or
> # gcc test.c -lncurses.3
> /usr/libexec/elf/ld: cannot find -lncurses.3
> 
> I have an error. Why?

Maybe it would help a bit if you told us exactly what you are trying to
accomplish.  In general, you never need to specify the version of the
library you want to link against; the linker will find either the
numerically largest, or the first one in the search path (others would
need to clarify that), and put its version number into the executable
file.  In general, the numerically largest one *will* be the first one
in the search path (the others are there mostly for compatibility), so
you will have no problems.

In this particular case, a program which is linked with -lncurses will
pick up libncurses.so.5 from /usr/lib, and use the 'right' version of
the library for your system.  The .3 library is there only for
compatibility with older programs that you only get as binaries; in the
binary executable, the linker has put a dependency on libncurses.so.3,
so that's the library that will be used for that particular program.
For programs you are developing, the linker will record a dependency on
.5, and all will work just fine.

Unless.. unless there really is a reason that you would want to link a
program against the older (or, in general, the non-default) version of a
library; is there such a reason, and what is it? :)

G'luck,
Peter

-- 
Peter Pentchev  [EMAIL PROTECTED]        [EMAIL PROTECTED]
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
I am jealous of the first word in this sentence.

Attachment: msg33543/pgp00000.pgp
Description: PGP signature

Reply via email to