📄 autobook_80.html
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on September, 12 2004 by texi2html 1.64 --><!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --><HEAD><TITLE>Autoconf, Automake, and Libtool: Installing a Library</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: Installing a Library"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: Installing a Library"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"><script language="Javascript"><!-- // Check the browser version. function checkVersion() { if (navigator.appVersion.charAt(0)>=3) return true; if (navigator.appVersion.charAt(0)>=4) return true; else return false; } if (checkVersion()) { homeon = new Image(); homeon.src = "homeon.png"; homeoff = new Image(); homeoff.src = "home.png"; tocon = new Image(); tocon.src = "tocon.png"; tocoff = new Image(); tocoff.src = "toc.png"; indexon = new Image(); indexon.src = "indexon.png"; indexoff = new Image(); indexoff.src = "index.png"; helpon = new Image(); helpon.src = "helpon.png"; helpoff = new Image(); helpoff.src = "help.png"; backon = new Image(); backon.src = "backon.png"; backoff = new Image(); backoff.src = "back.png"; forwardon = new Image(); forwardon.src = "forwardon.png"; forwardoff = new Image(); forwardoff.src = "forward.png"; prevon = new Image(); prevon.src = "prevon.png"; prevoff = new Image(); prevoff.src = "prev.png"; nexton = new Image(); nexton.src = "nexton.png"; nextoff = new Image(); nextoff.src = "next.png"; upon = new Image(); upon.src = "upon.png"; upoff = new Image(); upoff.src = "up.png"; } function img_act(imgName) { if (checkVersion()) { imgOn = eval(imgName + "on.src"); document [imgName].src = imgOn; } } function img_inact(imgName) { if (checkVersion()) { imgOff = eval(imgName + "off.src"); document [imgName].src = imgOff; } }// --></SCRIPT></HEAD><BODY LANG="EN" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#6688AA" VLINK="#336688" ALINK="#808080"><A NAME="SEC80"></A><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10><TR VALIGN="TOP"><TD ALIGN="MIDDLE" WIDTH=50 BGCOLOR="#e6e6e6"><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_79.html#SEC79" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: Executing Uninstalled Binaries" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_81.html#SEC81" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: Installing an Executable" ALIGN="MIDDLE" NAME="next"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_81.html#SEC81" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Installing an Executable" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_68.html#SEC68" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: Introducing GNU Libtool" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_83.html#SEC83" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: Using GNU Libtool" ALIGN="MIDDLE" NAME="forward"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook.html#SEC_Top" onMouseover="img_act('home')" onMouseout="img_inact('home')"><IMG SRC="home.png" BORDER="0" ALT="Top: Autoconf, Automake, and Libtool" ALIGN="MIDDLE" NAME="home"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_toc.html#SEC_Contents" onMouseover="img_act('toc')" onMouseout="img_inact('toc')"><IMG SRC="toc.png" BORDER="0" ALT="Contents: Table of Contents" ALIGN="MIDDLE" NAME="toc"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_285.html#SEC285" onMouseover="img_act('index')" onMouseout="img_inact('index')"><IMG SRC="index.png" BORDER="0" ALT="Index: Index" ALIGN="MIDDLE" NAME="index"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_abt.html#SEC_About" onMouseover="img_act('help')" onMouseout="img_inact('help')"><IMG SRC="help.png" BORDER="0" ALT="About: About this document" ALIGN="MIDDLE" NAME="help"></A></TD></TR></TABLE></TD><TD ALIGN="LEFT"><H2> 10.6 Installing a Library </H2><!--docid::SEC80::--><P>Now that the library and an executable which links with it have beensuccessfully built, they can be installed. For the sake of this exampleI will <CODE>cp</CODE> the objects to their destination, though<CODE>libtool</CODE> would be just as happy if I were to use<CODE>install</CODE> with the long, requisite list of parameters.</P><P>It is important to install the library to the <SAMP>`-rpath'</SAMP> destinationwhich was specified when it was linked earlier, or at least that it bevisible from that location when the runtime loader searches for it. Thisrule is not enforced by <CODE>libtool</CODE>, since it is often desirableto install libraries to a <EM>staging</EM><A NAME="DOCF17" HREF="autobook_fot.html#FOOT17">(17)</A> area.Of course, the package must ultimately install the library to the specified<SAMP>`-rpath'</SAMP> destination for it to work correctly, like this: </P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>$ libtool cp libtrim.la /usr/local/libcp .libs/libtrim.sl.0.0 /usr/local/lib/libtrim.sl.0.0(cd /usr/local/lib && rm -f libtrim.sl.0 && \ln -s libtrim.sl.0.0 libtrim.sl.0)(cd /usr/local/lib && rm -f libtrim.sl && \ln -s libtrim.sl.0.0 libtrim.sl)chmod 555 /usr/local/lib/libtrim.sl.0.0cp .libs/libtrim.lai /usr/local/lib/libtrim.lacp .libs/libtrim.a /usr/local/lib/libtrim.aranlib /usr/local/lib/libtrim.achmod 644 /usr/local/lib/libtrim.a----------------------------------------------------------------------Libraries have been installed in: /usr/local/libIf you ever happen to want to link against installed librariesin a given directory, LIBDIR, you must either use libtool, andspecify the full pathname of the library, or use -LLIBDIRflag during linking and do at least one of the following: - add LIBDIR to the SHLIB_PATH environment variable during execution - use the -Wl,+b -Wl,LIBDIR linker flagSee any operating system documentation about shared libraries formore information, such as the ld(1) and ld.so(8) manual pages.----------------------------------------------------------------------</FONT></pre></td></tr></table></P><P>Again, <CODE>libtool</CODE> takes care of the details for you. Both thestatic and shared archives are copied into the installation directoryand their access modes are set appropriately. <CODE>libtool</CODE><I>blesses</I> the static archive again with <CODE>ranlib</CODE>, which wouldbe easy to forget without the benefit of <CODE>libtool</CODE>, especiallyif I develop on a host where the library will continue to work withoutthis step. Also, <CODE>libtool</CODE> creates the necessary links for theshared archive to conform with HP-UXs library versioning rules.Compare this to what you see with the equivalent commands running onGNU/Linux to see how <CODE>libtool</CODE> applies these rulesaccording to the requirements of its host. The block of text<CODE>libtool</CODE> shows at the end of the installation serves to explainhow to link executables against the newly installed library onHP-UX and how to make sure that the executables linked against itwill work. Of course, the best way to ensure this is to use<CODE>libtool</CODE> to perform the linking. I'll leave the details oflinking against an installed Libtool library as an exercise - everythingyou need to know can be extrapolated from the example of linking againstan uninstalled Libtool library, See section <A HREF="autobook_75.html#SEC75">10.3 Linking an Executable</A>.</P><P>On some architectures, even shared archives need to be <I>blessed</I> oninstallation. For example, GNU/Linux requires that<CODE>ldconfig</CODE> be run when a new library is installed. Typically, alibrary will be installed to its target destination after being built,in which case <CODE>libtool</CODE> will perform any necessary <I>blessing</I>during installation. Sometimes, when building a binary package forinstallation on another machine, for example, it is not desirable toperform the <I>blessing</I> on the build machine. No problem,<CODE>libtool</CODE> takes care of this too! <CODE>libtool</CODE> will detectif you install the library to a destination other than the one specifiedin the <SAMP>`-rpath'</SAMP> argument passed during the archive link, and willsimply remind you what needs to be done before the library can be used:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>$ mkdir -p /usr/local/stow/hello-1.0/lib$ libtool cp libtrim.la /usr/local/stow/hello-1.0/libcp .libs/libtrim.sl.0.0 /usr/local/stow/hello-1.0/lib/libtrim.sl.0.0(cd /usr/local/stow/hello-1.0/lib && rm -f libtrim.sl.0 && \ln -s libtrim.sl.0.0 libtrim.sl.0)(cd /usr/local/stow/hello-1.0/lib && rm -f libtrim.sl && \ln -s libtrim.sl.0.0 libtrim.sl)chmod 555 /usr/local/stow/hello-1.0/lib/libtrim.sl.0.0cp .libs/libtrim.lai /usr/local/stow/hello-1.0/lib/libtrim.lacp .libs/libtrim.a /usr/local/stow/hello-1.0/lib/libtrim.aranlib /usr/local/stow/hello-1.0/lib/libtrim.achmod 644 /usr/local/stow/hello-1.0/lib/libtrim.alibtool: install: warning: remember to runlibtool: install: warning: libtool --finish /usr/local/lib</FONT></pre></td></tr></table></P><P>If you will make the installed libraries visible in the destinationdirectory with symbolic links, you need to do whatever it is you do tomake the library visible, and then <I>bless</I> the library in <EM>that</EM>location with the <CODE>libtool --finish /usr/local/lib</CODE> command:</P><P><TABLE width=100%><tr><td> </td><td class=example bgcolor=#6688aa><br><pre>$ cd /usr/local/stow$ stow hello-1.0$ libtool --finish /usr/local/lib</pre></td></tr></table></P><P>If you are following the examples so far, you will also need to installthe Libtool library, <TT>`libhello.la'</TT>, before you move on to the nextsection:</P><P><TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>$ libtool cp libhello.la /usr/local/libcp .libs/libhello.sl.0.0 /usr/local/lib/libhello.sl.0.0(cd /usr/local/lib && rm -f libhello.sl.0 && \ln -s libhello.sl.0.0 libhello.sl.0)(cd /usr/local/lib && rm -f libhello.sl && \ln -s libhello.sl.0.0 libhello.sl)chmod 555 /usr/local/lib/libhello.sl.0.0cp .libs/libhello.lai /usr/local/lib/libhello.lacp .libs/libhello.a /usr/local/lib/libhello.aranlib /usr/local/lib/libhello.achmod 644 /usr/local/lib/libhello.a----------------------------------------------------------------------Libraries have been installed in: /usr/local/libIf you ever happen to want to link against installed librariesin a given directory, LIBDIR, you must either use libtool, andspecify the full pathname of the library, or use -LLIBDIRflag during linking and do at least one of the following: - add LIBDIR to the SHLIB_PATH environment variable during execution - use the -Wl,+b -Wl,LIBDIR linker flagSee any operating system documentation about shared libraries formore information, such as the ld(1) and ld.so(8) manual pages.----------------------------------------------------------------------</FONT></pre></td></tr></table></P><P>Once a Libtool library is installed, binaries which link against it will hardcode the path to the Libtool library, as specified with the<SAMP>`-rpath'</SAMP> switch when the library was built. <CODE>libtool</CODE>always encodes the installation directory into a Libtool library forjust this purpose. Hardcoding directories in this way is a good thing,because binaries linked against such libraries will continue to work ifthere are several incompatible versions of the library visible to theruntime loader (say a Trojan <TT>`libhello'</TT> in a user's<CODE>LD_LIBRARY_PATH</CODE>, or a test build of the next release). Thedisadvantage to this system is that if you move libraries to newdirectories, executables linked in this way will be unable to find thelibraries they need. Moving any library is a bad idea however, doublyso for a Libtool library which has its installation directory encodedinternally, so the way to avoid problems of this nature is to not movelibraries around after installation!</P><P><A NAME="Installing an Executable"></A></TR></TABLE><BR> <FONT SIZE="-1">This document was generatedby <I>Gary V. Vaughan</I> on <I>September, 12 2004</I>using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html"><I>texi2html</I></A></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -