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

📄 autobook_188.html

📁 Autoconf使用手册
💻 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: A Loadable Module</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: A Loadable Module"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: A Loadable Module"><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="SEC188"></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_187.html#SEC187" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: Unloading a Module" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_189.html#SEC189" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: Interpreting Commands from a File" 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_189.html#SEC189" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Interpreting Commands from a File" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_182.html#SEC182" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: A Complex GNU Autotools Project" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_191.html#SEC191" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: M4" 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> 20.2 A Loadable Module </H2><!--docid::SEC188::--><P>A feature of the Sic interpreter is that it will use the <SAMP>`unknown'</SAMP>built-in to handle any command line which is not handled by any of theother registered built-in callback functions.  This mechanism is verypowerful, and allows me to lookup unhandled built-ins in the user's<SAMP>`PATH'</SAMP>, for instance.</P><P>Before adding any modules to the project, I have created a separatesubdirectory, <TT>`modules'</TT>, to put the module source code into.  Notforgetting to list this new subdirectory in the <CODE>AC_OUTPUT</CODE> macroin <TT>`configure.in'</TT>, and the <CODE>SUBDIRS</CODE> macro in the top level<TT>`Makefile.am'</TT>, a new <TT>`Makefile.am'</TT> is needed to build theloadable modules:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P><CODE>pkglibdir</CODE> is a Sic specific directory where modules will beinstalled, See section <A HREF="autobook_105.html#SEC105">Installing and Uninstalling Configured Packages</A>.</P><P><BLOCKQUOTE>For a library to be maximally portable, it should be written so that itdoes not require back-linking<A NAME="DOCF47" HREF="autobook_fot.html#FOOT47">(47)</A> toresolve its own symbols.  That is, if at all possible you should designall of your libraries (not just dynamic modules) so that all of theirsymbols can be resolved at linktime.  Sometimes, it is impossible orundesirable to architect your libraries and modules in this way.  Inthat case you sacrifice the portability of your project to platformssuch as AIX and Windows.</BLOCKQUOTE><P>The key to building modules with libtool is in the options that arespecified when the module is linked.  This is doubly true when themodule must work with libltdl's dlpreopening mechanism.</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>Sic modules are built without a <SAMP>`lib'</SAMP> prefix (<SAMP>`-module'</SAMP>),and without version suffixes (<SAMP>`-avoid-version'</SAMP>).  All of theundefined symbols are resolved at linktime by <TT>`libsic.la'</TT>, hence<SAMP>`-no-undefined'</SAMP>.</P><P>Having added <TT>`ltdl.c'</TT> to the <TT>`sic'</TT> subdirectory, and calledthe <CODE>AC_LIB_LTDL</CODE> macro in <TT>`configure.in'</TT>, <TT>`libsic.la'</TT>cannot build correctly on those architectures which do not supportback-linking.  This is because <TT>`ltdl.c'</TT> simply abstracts the native<CODE>dlopen</CODE> API with a common interface, and that local interfaceoften requires that a special library be linked -- <TT>`-ldl'</TT> on linux,for example.  <CODE>AC_LIB_LTDL</CODE> probes the system to determine the nameof any such dlopen library, and allows you to depend on it in a portableway by using the configure substitution macro, <SAMP>`@LIBADD_DL@'</SAMP>.  IfI were linking a <CODE>libtool</CODE> compiled libltdl at thisjuncture, the system library details would have already been taken careof.  In this project, I have bypassed that mechanism by compiling andlinking <TT>`ltdl.c'</TT> myself, so I have altered <TT>`sic/Makefile.am'</TT>to use <SAMP>`@LIBADD_DL@'</SAMP>:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>Having put all this infrastructure in place, the code for the<SAMP>`unknown'</SAMP> module is a breeze (helper functions omitted forbrevity):</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre></pre></td></tr></table></P><P>In the first instance, notice that I have used the preprocessor toredefine the entry point functions to be compatible with libltdls<CODE>dlpreopen</CODE>, hence the <CODE>unknown_LTX_builtin_table</CODE><CODE>cpp</CODE> macro.  The <SAMP>`unknown'</SAMP> handler function itself looksfor a suitable executable in the user's path, and if something suitable<EM>is</EM> found, executes it.</P><P>Notice that Libtool doesn't relink dependent libraries (<TT>`libsic'</TT>depends on <TT>`libcommon'</TT>, for example) on my GNU/Linux system,since they are not required for the static library in any case, andbecause the dependencies are also encoded directly into the sharedarchive, <TT>`libsic.so'</TT>, by the original link.  On the other hand,Libtool <EM>will</EM> relink the dependent libraries if that is necessaryfor the target host.</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>$ make/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I.. \-I.. -I.. -I../sic -I../sic -I../src -I../src    -g -O2 -c unknown.cmkdir .libsgcc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I.. -I../sic -I../sic -I../src \-I../src -g -O2 -Wp,-MD,.deps/unknown.pp -c unknown.c  -fPIC -DPIC \-o .libs/unknown.logcc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I.. -I../sic -I../sic -I../src \I../src -g -O2 -Wp,-MD,.deps/unknown.pp -c unknown.c -o unknown.o \&#62;/dev/null 2&#62;&#38;1mv -f .libs/unknown.lo unknown.lo/bin/sh ../libtool --mode=link gcc  -g -O2  -o unknown.la -rpath \/usr/local/lib/sic -no-undefined -module -avoid-version unknown.lo \../sic/libsic.larm -fr .libs/unknown.la .libs/unknown.* .libs/unknown.*gcc -shared  unknown.lo -L/tmp/sic/sic/.libs ../sic/.libs/libsic.so \-lc  -Wl,-soname -Wl,unknown.so -o .libs/unknown.soar cru .libs/unknown.a  unknown.ocreating unknown.la(cd .libs &#38;&#38; rm -f unknown.la &#38;&#38; ln -s ../unknown.la unknown.la)$ ./libtool --mode=execute ldd ./unknown.la        libsic.so.0 =&#62; /tmp/sic/.libs/libsic.so.0 (0x40002000)        libc.so.6 =&#62; /lib/libc.so.6 (0x4000f000)        libcommon.so.0 =&#62; /tmp/sic/.libs/libcommon.so.0 (0x400ec000)        libdl.so.2 =&#62; /lib/libdl.so.2 (0x400ef000)        /lib/ld-linux.so.2 =&#62; /lib/ld-linux.so.2 (0x80000000)</pre></td></tr></table></P><P>After compiling the rest of the tree, I can now use the <SAMP>`unknown'</SAMP>module:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>$ SIC_MODULE_PATH=`cd ../modules; pwd` ./sic] echo hello!command "echo" not found.] load unknown] echo hello!hello!] unload unknown] echo hello!command "echo" not found.] exit$</pre></td></tr></table></P><P><A NAME="Interpreting Commands from a File"></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 + -