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

📄 autobook_254.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 configure.in for DLLs</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: A configure.in for DLLs"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: A configure.in for DLLs"><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="SEC254"></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_253.html#SEC253" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: A Makefile.am for DLLs" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_255.html#SEC255" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: Handling Data Exports from DLLs" 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_255.html#SEC255" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Handling Data Exports from DLLs" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_251.html#SEC251" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: DLLs with Libtool" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_257.html#SEC257" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: Package Installation" 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"><H3> 25.4.3 A configure.in for DLLs </H3><!--docid::SEC254::--><P><TT>`configure.in'</TT> is used to generate the <TT>`configure'</TT> script:<TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre># Process this file with autoconf to create configure.AC_INIT(hello.h)AM_CONFIG_HEADER(config.h:config.hin)AM_INIT_AUTOMAKE(hello, 1.0)AC_PROG_CCAM_PROG_CC_STDCAC_C_CONSTAM_PROG_LIBTOOLAC_OUTPUT(Makefile)</pre></td></tr></table></P><P>The <SAMP>`AC_PROG_CC'</SAMP> and <SAMP>`AM_PROG_CC_STDC'</SAMP> macros in the<TT>`configure.in'</TT> above will conspire to find a suitable compiler forthe C code in this example, and to discover any extra switches requiredto put that compiler into an <FONT SIZE="-1">ANSI</FONT> mode.  I have used the<CODE>const</CODE> keyword in the sources, so I need to specify the<SAMP>`AC_C_CONST'</SAMP> macro, in case the compiler doesn't understand it, andfinally I have specified the <SAMP>`AM_PROG_LIBTOOL'</SAMP> macro since I wantthe library to be built with Libtool.</P><P>In order to set the build environment up we need to create theautogenerated files:</P><P><TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>$ lsMakefile.in    hello.c   main.cconfigure.in   hello.h$ aclocal$ autoheader$ libtoolize --force --copy$ automake --foreign --add-missing --copyautomake: configure.in: installing ./install-shautomake: configure.in: installing ./mkinstalldirsautomake: configure.in: installing ./missing$ autoconf$ lsMakefile.am    config.hin     hello.c       ltmain.sh      stamp-h.inMakefile.in    config.sub     hello.h       main.caclocal.m4     configure      install-sh    missingconfig.guess   configure.in   ltconfig      mkinstalldirs</FONT></pre></td></tr></table></P><P>If you have already tried to build DLLs with Libtool, you haveprobably noticed that the first point of failure is during theconfiguration process.  For example, running the new <CODE>configure</CODE>script you might see:</P><P><TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>...checking if libtool supports shared libraries... yeschecking if package supports dlls... nochecking whether to build shared libraries... no...</FONT></pre></td></tr></table></P><P><A NAME="IDX89"></A><CODE>libtool</CODE> provides a macro, <SAMP>`AC_LIBTOOL_WIN32_DLL'</SAMP>, whichmust be added to a package's <TT>`configure.in'</TT> to communicate to the<CODE>libtool</CODE> machinery that the package supports DLLs.Without this macro, <CODE>libtool</CODE> will never try to build a DLLon Windows.  Add this macro to <TT>`configure.in'</TT> before the<SAMP>`AM_PROG_LIBTOOL'</SAMP> macro, and try again:</P><P><TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>$ makecd . &#38;&#38; aclocalcd . &#38;&#38; automake --foreign Makefilecd . &#38;&#38; autoconf...checking if libtool supports shared libraries... yeschecking if package supports dlls... yeschecking whether to build shared libraries... yes...gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -Wp,-MD,.deps/hello.pp \-c  -DDLL_EXPORT -DPIC hello.c -o .libs/hello.logcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -Wp,-MD,.deps/hello.pp \-c hello.c -o hello.o &#62;/dev/null 2&#62;&#38;1mv -f .libs/hello.lo hello.lo...gcc -g -O2 -o ./libs/hello main.o .libs/libimp-hello-0-0-0.a \-Wl,--rpath -Wl,/usr/local/libcreating hello...$ ./helloHello, World!</FONT></pre></td></tr></table></P><P>If you run this and watch the full output of the <SAMP>`make'</SAMP> command,Libtool uses a rather contorted method of building DLLs, withseveral invocations each of <CODE>dlltool</CODE> and <CODE>gcc</CODE>.  I haveomitted these from the example above, since they really are very ugly,and in any case are almost incomprehensible to most people.  To see itall in its full horror you can always examine the output after runningthe commands yourself!  In a future release of Cygwin, recent work onthe binutils linker by DJ Delorie, will allow <CODE>gcc</CODE> to linkDLLs in a single pass using the same syntax used on other systemsto produce shared libraries. Libtool will adopt this method when itbecomes available, deprecating the use of <CODE>dlltool</CODE>.</P><P>I have extracted the interesting lines from amongst the many calls to<CODE>dlltool</CODE><A NAME="DOCF67" HREF="autobook_fot.html#FOOT67">(67)</A> and<CODE>gcc</CODE> generated by <CODE>make</CODE> in the shell log.  The mainthing to notice is that we have a <SAMP>`hello'</SAMP> binary, which isexecutable, and which gives the right result when we run it! From thepartial log above, it certainly appears that it has built<SAMP>`libhello'</SAMP> as a DLL and linked that into <SAMP>`hello'</SAMP>, butjust to double check we can use <CODE>ldd</CODE><A NAME="DOCF68" HREF="autobook_fot.html#FOOT68">(68)</A>:</P><P><TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>$ libtool --mode=execute ldd ./hellolt-hello.exe    -&#62; /tmp/.libs/lt-hello.exelibhello-0-0-0.dll      -&#62; /tmp/.libs/libhello-0-0-0.dllcygwin1.dll     -&#62; /usr/bin/cygwin1.dllkernel32.dll    -&#62; /WINNT/system32/kernel32.dllntdll.dll       -&#62; /WINNT/system32/ntdll.dlladvapi32.dll    -&#62; /WINNT/system32/advapi32.dlluser32.dll      -&#62; /WINNT/system32/user32.dllgdi32.dll       -&#62; /WINNT/system32/gdi32.dllrpcrt4.dll      -&#62; /WINNT/system32/rpcrt4.dll</FONT></pre></td></tr></table></P><P>So now you know how to build and link a simple Windows DLL usingGNU Autotools:  You add <SAMP>`-no-undefined'</SAMP> to the Libtool library<SAMP>`LDFLAGS'</SAMP>, and include the <SAMP>`AC_LIBTOOL_WIN32_DLL'</SAMP> macro inyour <TT>`configure.in'</TT>.</P><P><A NAME="Handling Data Exports from DLLs"></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 + -