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

📄 449-452.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Configuration and Installation:Programming in Linux</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=1558285660//-->

<!--TITLE=Linux Configuration and Installation//-->

<!--AUTHOR=Patrick Volkerding//-->

<!--AUTHOR=Kevin Reichard//-->

<!--AUTHOR=Eric Foster//-->

<!--PUBLISHER=IDG Books Worldwide, Inc.//-->

<!--IMPRINT=M & T Books//-->

<!--CHAPTER=10//-->

<!--PAGES=449-452//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="447-449.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="452-455.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">ELF Files</FONT></H4>

<P>This version of Linux uses a new object module format called ELF, short for Executable and Linking Format. Programs compiled with ELF differ from those compiled in the older <B>a.out</B> format. ELF provides better support for shared libraries, the primary reason for this migration. Shared libraries save on memory usage when you run more than one program at a time, especially more than one X Window program.</P>

<P>Normally, you won&#146;t have to pay attention to ELF or <B>a.out</B> issues, except for one thing: the <B>a.out</B> libraries are not compatible with the ELF libraries. This is especially true for shared libraries.</P>

<P>Thus, you need to be careful about any Linux binary programs you acquire. If you compile everything from source code, then you&#146;re OK, as Linux will use the libraries you have on your system.</P>

<P>But if you pick up applications in precompiled binary format, for example, Netscape Navigator or NCSA Mosaic, you have to ensure that you have the proper shared libraries as expected by the application, or the program simply won&#146;t run.</P>

<P>When you install Linux (or any time later if you run the <B>setup</B> program), you can install both the <B>a.out</B> and the ELF libraries. If you have the disk space, you should load both. If you need to choose one or the other, go with ELF, as everything in the Linux world is migrating to ELF.</P>

<P>To see what systems your linker, <B>ld</B>, is configured for, try the following command:</P>

<!-- CODE SNIP //-->

<PRE>

     ld -V

</PRE>

<!-- END CODE SNIP //-->

<P>You should see output like the following:

</P>

<!-- CODE //-->

<PRE>

     ld version cygnus-2.6 (with BFD 2.6.0.14)

       Supported emulations:

        elf_i386

        i386linux

        i386coff

        m68kelf

        m68klinux

        sun4

        elf32_sparc

</PRE>

<!-- END CODE //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The <I>sparc</I>, <I>sun4</I>, and <I>m68k</I> (Motorola 68000) are for cross-compiling. Chances are you won&#146;t use these options.<HR></FONT>

</BLOCKQUOTE>

<P>By default, <B>gcc</B> will compile to ELF format. To verify, use the <B>file</B> command on any executable file, such as the <B>chap10</B> file we created earlier:</P>

<!-- CODE SNIP //-->

<PRE>

     file chap10

</PRE>

<!-- END CODE SNIP //-->

<P>You should see output like the following:

</P>

<!-- CODE SNIP //-->

<PRE>

     chap10: ELF 32-bit LSB executable i386 (386 and up) Version 1

</PRE>

<!-- END CODE SNIP //-->

<P>This indicates that the default object file format on Linux is now ELF, as expected.

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The term <B>a.out</B>, unfortunately, means different things in different contexts. If you compile a C program with <B>gcc</B>, the default output filename remains <B>a.out</B>. Even so, this <B>a.out</B> file will appear in ELF object file format, not the older object file format, called <B>a.out</B> format. This is yet another confusing part of Linux.<HR></FONT>

</BLOCKQUOTE>

<P>If for some reason you need to force <B>gcc</B> to compile in <B>a.out</B> format, you can use the following command in place of <B>gcc</B>:</P>

<!-- CODE SNIP //-->

<PRE>

     gcc -b i486-linuxaout -c foo.c -o foo

</PRE>

<!-- END CODE SNIP //-->

<P>This command requires the <B>a.out</B> libraries. If you did not load them, this command will fail.</P>

<H4 ALIGN="LEFT"><A NAME="Heading8"></A><FONT COLOR="#000077">Linux Shared Libraries</FONT></H4>

<P>Linux supports a great concept called <I>shared libraries</I>. Because so many Linux programs link in very large libraries, particularly X Window libraries, the program size tends to grow. When you run these programs, they take up more memory (real and virtual). To help alleviate this problem, Linux supports shared libraries, similar to Windows DLLs, or Dynamic Link Libraries. The whole purpose is that many programs can reference a single copy of the library loaded into memory. For X Window programs, this saves a lot of RAM.</P>

<P>The problem with Linux shared libraries is that they are very tightly linked to their version numbers. If you upgrade your version of Linux, many old applications may still demand the old versions of the shared libraries, and you may no longer have these old versions on your system. If you have a lot of Linux programs that came only in binary format (Netscape Navigator is a common program in this category), you either need to load the old shared libraries or wait until all the programs you use get upgraded. If you have the source code for the program, you can simply recompile and relink, and everything should be OK.</P>

<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Programming with X</FONT></H4>

<P>Linux comes with a number of X Window libraries, ready both for you to program with and for you to use when compiling freeware X Window applications. Unfortunately, Linux does not come with the Motif libraries, which are necessary to compile a number of neat programs, including the Mosaic Internet browser. (You can purchase the Motif libraries from a number of third parties, though; see Appendix A for details. Or, you can try a freeware version of the Motif API, called LessTif, which is described later.)

</P>

<P>When compiling X programs, you normally don&#146;t have to do anything special to link, other than adding the X libraries to your <B>cc</B> command line. The X Window include files should be in the proper place, <B>/usr/include/X11</B> (actually a symbolic link to <B>/usr/X11R6/include/X11</B>, but good enough for the compiler).</P>

<P>To compile and link an X program, you can use the following command line:</P>

<!-- CODE SNIP //-->

<PRE>

     cc -o foo foo.c -lXaw -lXt -lXext -lX11 -lSM -lICE

</PRE>

<!-- END CODE SNIP //-->

<P>The <I>-l</I> option tells <B>cc</B> (really <B>ld</B>, as called by <B>cc</B>) to link in the named library. These libraries provide commonly used functions. The ones listed earlier provide X Window functions for the program. Thus, the <I>-lXaw</I> option tells <B>ld</B> to link in the Xaw library. By convention, this library file will be named <B>libXaw.a</B> for a static library and <B>libXaw.so</B> for a shared library.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>For more information on X and Motif programming, see URL <A HREF="http://ourworld.compuserve.com/homepages/efjohnson/motif.htm">http://ourworld.compuserve.com/homepages/efjohnson/motif.htm</A> on the World Wide Web.<HR></FONT>

</BLOCKQUOTE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="447-449.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="452-455.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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