Date: Fri, 12 Apr 2002 12:24:08 +0300 From: Peter Pentchev <roam@ringlet.net> To: Dmitry Mottl <dima@sinp.msu.ru> Cc: freebsd-hackers@FreeBSD.org Subject: Re: dynamic libraries Message-ID: <20020412122408.C365@straylight.oblivion.bg> In-Reply-To: <Pine.BSF.4.43.0204121308470.4449-100000@BigKing.sinp.msu.ru>; from dima@sinp.msu.ru on Fri, Apr 12, 2002 at 01:10:19PM %2B0400 References: <Pine.BSF.4.43.0204121308470.4449-100000@BigKing.sinp.msu.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
--+nBD6E3TurpgldQp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 12, 2002 at 01:10:19PM +0400, Dmitry Mottl wrote: > Hi, > sorry, for possible offtopic, but freebsd-question said nothing >=20 > How can I link C program with different versions of the same library? >=20 > # /sbin/ldconfig -r | grep ncurses > 5:-lncurses.5 =3D> /usr/lib/libncurses.so.5 > 84:-lncurses.3 =3D> /usr/lib/compat/libncurses.so.3 > # gcc test.c -lncurses > # ldd a.out > a.out: > libncurses.so.5 =3D> /usr/lib/libncurses.so.5 (0x28065000) > libc.so.4 =3D> /usr/lib/libc.so.4 (0x280a7000) >=20 >=20 > But if I explicitly set version of library: > # gcc test.c -lncurses.5 > /usr/libexec/elf/ld: cannot find -lncurses.5 >=20 > or > # gcc test.c -lncurses.3 > /usr/libexec/elf/ld: cannot find -lncurses.3 >=20 > 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 =2E5, 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 --=20 Peter Pentchev roam@ringlet.net roam@FreeBSD.org 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. --+nBD6E3TurpgldQp Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjy2p7gACgkQ7Ri2jRYZRVOyGgCeKkMgsxsu7OSF4zcSoTayOupd jf0An2v7RFPNn0i3NnMtXNUtG7OJIDUh =iZqu -----END PGP SIGNATURE----- --+nBD6E3TurpgldQp-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020412122408.C365>