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

📄 447-449.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=447-449//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

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

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

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

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P><FONT SIZE="+1"><B>Working with Cc</B></FONT></P>

<P>In normal operation, the <B>cc</B> command executes a number of other commands under the hood. One such command is <B>cpp</B>. The <B>cpp</B> command is the C preprocessor. This reads a C program file, a <I>.c</I> file, and expands any # directives. In the short program you typed in earlier, the <I>#include</I> directive means to include the file <B>stdio.h</B>. That is, <B>cpp</B> reads in <B>stdio.h</B> and inserts the contents right at the <I>#include</I> directive. Most C programs use one or more include files.</P>

<P>These include files are normally stored in <B>/usr/include</B>. If you use the angle brackets, (<B>&lt;</B>) and (<B>&gt;</B>), around an include filename, like <B>&lt;stdio.h&gt;</B>, this means that <B>cpp</B> looks for a file named <B>stdio.h</B> in the standard places, of which <B>/usr/include</B> is the default (the <I>-I</I> command-line parameter can add more directories to the include file search path; see Table 10.2 later). You can also use quotation marks (<B>&#147;</B>) around the filename.</P>

<TABLE WIDTH="100%"><CAPTION><B>Table 10.2</B> Cc Command-Line Parameters

<TR>

<TH WIDTH="30%" ALIGN="LEFT">Parameter

<TH WIDTH="70%" ALIGN="LEFT">Meaning

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD WIDTH="30%" VALIGN="TOP"><B>-I<I>directory</I></B>

<TD WIDTH="70%">Searches the given directory and <B><I>/usr/include</I></B> for include files

<TR>

<TD VALIGN="TOP"><B>-c <I>filename.c</I></B>

<TD>Compiles the file <I>filename.c</I> and builds the object module <I>filename.o</I>; this does not create an executable command

<TR>

<TD VALIGN="TOP"><B>-o <I>progname</I></B>

<TD>Names the executable program <I>progname</I>; the default name is <B>a.out</B>

<TR>

<TD><B>-g</B>

<TD>Compiles with debugging information

<TR>

<TD><B>-O</B>

<TD>Optimizes the program for best performance

<TR>

<TD><B>-l<I>Library</I></B>

<TD>Link in the named <I>library</I>

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>All C programs are built around the section labeled main(). The main() section (called a <I>function</I> in C parlance) is executed when the program starts. Our main() function simply calls the printf() function, which prints the text between the quotation marks to your screen. As you can tell, this is not a sophisticated program.</P>

<P>The <I>\n</I> character passed to printf() in our program means that a newline character is printed. This starts a new line. If you&#146;re used to a DOS machine, you&#146;ll note that UNIX uses a newline character where DOS uses a carriage return and then a new line. The backslash, <B>\</B>, is used as a special character in C programs. Usually, a backslash is combined with another character to make a nonprintable character, such as <B>\n</B> for a new line, <B>\t</B> for a tab, or <B>\a</B> for a bell.</P>

<H4 ALIGN="LEFT"><A NAME="Heading6"></A><FONT COLOR="#000077">Using the Cc Command</FONT></H4>

<P>The <B>cc</B> command uses a number of command-line parameters to tell it what to do and to allow you to fine-tune the process of building executable programs from C language text files. Table 10.2 lists commonly used <B>cc</B> command-line parameters.</P>

<P>Most UNIX compilers don&#146;t allow you to mix the <I>g</I> (include debugging information) and <I>O</I> (optimize) options, but the GNU C compiler used by Linux allows this.</P>

<P>There are many <B>cc</B> command-line options; use <B>man cc</B> to see them.</P>

<P><FONT SIZE="+1"><B>Linking with Libraries</B></FONT></P>

<P>For C programs, a <I>library</I> is a collection of commonly used routines that you can reuse in your programs. Most C programs require more than just the standard C library. If you look in <B>/usr/lib</B>, you&#146;ll see most of the libraries supported by Linux. Table 10.3 lists the major locations for Linux libraries.</P>

<TABLE WIDTH="100%"><CAPTION><B>Table 10.3</B> Locations for Linux Libraries

<TR>

<TH WIDTH="30%" ALIGN="LEFT">Directory

<TH WIDTH="70%" ALIGN="LEFT">Libraries

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD WIDTH="30%"><B>/usr/lib</B>

<TD WIDTH="70%">Main system libraries

<TR>

<TD><B>/usr/openwin/lib</B>

<TD>Open Look libraries like the Xview library

<TR>

<TD><B>/usr/X11R6/lib</B>

<TD>Most X Window libraries

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>To link with a given library, you use the <I>-l</I> command-line option to <B>cc</B>. To link with the X11 library, use <I>-lX11</I>; this is shorthand notion for linking in the library named <B>libX11.a</B> (or it&#146;s shared-library equivalent, <B>libX11.so</B>).</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

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

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

<TD><A HREF="449-452.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 + -