⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autobook_92.html

📁 Autoconf使用手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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: Convenience Libraries</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: Convenience Libraries"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: Convenience Libraries"><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="SEC92"></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_91.html#SEC91" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: Library Versioning" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_93.html#SEC93" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: A Large GNU Autotools Project" ALIGN="MIDDLE" NAME="next"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_83.html#SEC83" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Using GNU Libtool" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_83.html#SEC83" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: Using GNU Libtool" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_93.html#SEC93" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: A Large GNU Autotools Project" 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> 11.5 Convenience Libraries </H2><!--docid::SEC92::--><P>Sometimes it is useful to group objects together in an intermediatestage of a project's compilation to provide a useful handle for thatgroup without having to specify all of the individual objects everytime.  Convenience libraries are a portable way of creating such a<EM>partially linked</EM> object:  Libtool will handle all of thelow level details in a way appropriate to the target host.  This sectiondescribes the use of convenience libraries in conjunction withAutomake.  The principles of convenience libraries arediscussed in <A HREF="autobook_74.html#SEC74">Creating Convenience Libraries</A>.</P><P>The key to creating Libtool convenience libraries withAutomake is to use the<BR> <SAMP>`noinst_LTLIBRARIES'</SAMP> macro.  Forthe Libtool libraries named in this macro, Automake willcreate Libtool convenience libraries which can subsequently be linkedinto other Libtool libraries.</P><P>In this section I will create two convenience libraries, each in theirown subdirectory, and link them into a third Libtool library, which isultimately linked into an application.</P><P>If you want to follow this example, you should create a directorystructure to hold the sources by running the following shell commands:</P><P><TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>$ mkdir convenience$ cd convenience$ mkdir lib$ mkdir replace</FONT></pre></td></tr></table></P><P>The first convenience library is built from two source files in the<TT>`lib'</TT> subdirectory.</P><P><OL><LI><TT>`source.c'</TT>:<P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>This file defines a single function to display the cosine of itsargument on standard output, and consequently relies on animplementation of the <CODE>cos</CODE> function from the system libraries.Note the conditional inclusion of <TT>`config.h'</TT>, which will contain adefinition of <SAMP>`HAVE_MATH_H'</SAMP> if <TT>`configure'</TT> discovers a<TT>`math.h'</TT> system header (the usual location for the declaration of<CODE>cos</CODE>).  The <SAMP>`HAVE_CONFIG_H'</SAMP> guard is by convention, so thatthe source can be linked by passing the preprocessor macro definitionsto the compiler on the command line -- if <TT>`configure.in'</TT> does notuse <SAMP>`AM_CONFIG_HEADER'</SAMP> for instance.</P><P><LI><TT>`source.h'</TT>:<P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>For brevity, there is no <CODE>#ifndef SOURCE_H</CODE> guard.  The header isnot installed, so you have full control over where it is<CODE>#include</CODE>ed, and in any case, function declarations can be safelyrepeated if the header is accidentally processed more than once.  In areal program, it would be better to list the function parameters inthe declaration so that the compiler can do type checking.  This wouldlimit the code to working only with ANSI compilers, unless you alsouse a <CODE>PARAMS</CODE> macro to conditionally preprocess away theparameters when a K&#38;R compiler is used.  These details are beyondthe scope of this convenience library example, but are described in fullin <A HREF="autobook_51.html#SEC51">9.1.6 K&#38;R Compilers</A>.</OL><P>You also need a <TT>`Makefile.am'</TT> to hold the details of how thisconvenience library is linked:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>The <SAMP>`noinst_LTLIBRARIES'</SAMP> macro names the Libtool conveniencelibraries to be built in this directory, <TT>`library.la'</TT>.   Althoughnot required for compilation, <TT>`source.h'</TT> is listed in the<SAMP>`SOURCES'</SAMP> macro of <TT>`library.la'</TT> so that correct sourcedependencies are generated, and so that it is added to the distributiontarball by <CODE>automake</CODE>'s <SAMP>`dist'</SAMP> rule.</P><P>Finally, since the <CODE>foo</CODE> function relies on the <CODE>cos</CODE> functionfrom the system math library, <SAMP>`-lm'</SAMP> is named as a requiredlibrary in the <SAMP>`LIBADD'</SAMP> macro.  As with all Libtool libraries,interlibrary dependencies are maintained for convenience libraries sothat you need only list the libraries you are using directly when youlink your application later.  The libraries used by those libraries areadded by Libtool.</P><P>The parent directory holds the sources for the main executable,<TT>`main.c'</TT>, and for a (non-convenience) Libtool library,<TT>`error.c'</TT> &#38; <TT>`error.h'</TT>.</P><P>Like <TT>`source.h'</TT>, the functions exported from the Libtool library<TT>`liberror.la'</TT> are listed in <TT>`error.h'</TT>:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>The corresponding function definitions are in <TT>`error.c'</TT>:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>The <CODE>gratuitous()</CODE> function calls the <CODE>foo()</CODE> function definedin the <TT>`library.la'</TT> convenience library in the <TT>`lib'</TT>directory, hence <TT>`source.h'</TT> is included.</P><P>The definition of <CODE>error()</CODE> displays an error message to standarderror, along with the name of the program, <CODE>program_name</CODE>, which isset by calling <CODE>set_program_name()</CODE>.  This function, in turn,extracts the basename of the program from the full path using the systemfunction, <CODE>basename()</CODE>, and stores it in the library privatevariable, <CODE>program_name</CODE>.</P><P>Usually, <CODE>basename()</CODE> is part of the system C library, though oldersystems did not include it.  Because of this, there is no portableheader file that can be included to get a declaration, and you might seea harmless compiler warning due to the use of the function without adeclaration.  The alternative would be to add your own declaration in

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -