From owner-freebsd-hackers Fri Apr 12 2:24:27 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from south.nanolink.com (south.nanolink.com [217.75.134.10]) by hub.freebsd.org (Postfix) with SMTP id 2355437B404 for ; Fri, 12 Apr 2002 02:24:19 -0700 (PDT) Received: (qmail 69006 invoked from network); 12 Apr 2002 09:30:48 -0000 Received: from unknown (HELO straylight.ringlet.net) (212.116.140.125) by south.nanolink.com with SMTP; 12 Apr 2002 09:30:48 -0000 Received: (qmail 49273 invoked by uid 1000); 12 Apr 2002 09:24:08 -0000 Date: Fri, 12 Apr 2002 12:24:08 +0300 From: Peter Pentchev To: Dmitry Mottl Cc: freebsd-hackers@FreeBSD.org Subject: Re: dynamic libraries Message-ID: <20020412122408.C365@straylight.oblivion.bg> Mail-Followup-To: Dmitry Mottl , freebsd-hackers@FreeBSD.org References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="+nBD6E3TurpgldQp" Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: ; from dima@sinp.msu.ru on Fri, Apr 12, 2002 at 01:10:19PM +0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --+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