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

📄 488-491.html

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

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Programming in C&#43;&#43;</TITLE>

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

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Sams//-->

<!--CHAPTER=27//-->

<!--PAGES=488-491//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="485-488.html">Previous</A></TD>

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

<TD><A HREF="491-494.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading5"></A><FONT COLOR="#000077">GCC Options</FONT></H3>

<P>This section describes some of the GCC options that are most commonly used. First we&#146;ll talk about some of the options that can be used both with C and C&#43;&#43; and then talk about C&#43;&#43; specific options. Any of the compiler options that you use with C you can use with C&#43;&#43; as well, but some of them may not make any sense in the context of a C&#43;&#43; compile. If you specify options that don&#146;t make sense, the compiler just ignores them.

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Tip:&nbsp;&nbsp;</B><BR>When you are compiling C&#43;&#43; programs, it is easiest to use the <TT>g&#43;&#43;</TT> script. This sets all the default C&#43;&#43; options so you don&#146;t have to.<HR></FONT>

</BLOCKQUOTE>

<P>A great number of compiler options can be passed to GCC. Many of these options are specific to a certain hardware platform or are for making fine-tuning adjustments to the code that is produced. You will probably never use any of these kinds of options. The options covered in this chapter are those that you will use on a regular basis.

</P>

<P>Many of the GCC options consist of more than one character. For this reason, you must specify each option with its own hyphen and not group options after a single hyphen as you can with most Linux commands.</P>

<P>When you compile a program using GCC without any command-line options, it creates an executable file (assuming that the compile is successful) and calls it <TT>a.out</TT>. For example, the following command creates a file named <TT>a.out</TT> in the current directory:</P>

<!-- CODE SNIP //-->

<PRE>

gcc test.C

</PRE>

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

<P>To specify a name other than <TT>a.out</TT> for the executable file, you can use the <TT>-o</TT> compiler option. For example, to compile a C&#43;&#43; program file named <TT>count.C</TT> (the capital <TT>C</TT> is used to show C&#43;&#43; code, as opposed to a small <TT>c</TT> for C code) into an executable file named <TT>count</TT>, type the following command:</P>

<!-- CODE SNIP //-->

<PRE>

gcc -o count count.C

</PRE>

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

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Warning:&nbsp;&nbsp;</B><BR>Don&#146;t put a space after the -o option!

<P>When you are using the <TT>-o</TT> option, the executable filename must occur directly after the <TT>-o</TT> on the command line.<HR></FONT>

</BLOCKQUOTE>

</P>

<P>Other compiler options allow you to specify how far you want the compile to proceed. The <TT>-c</TT> option tells GCC to compile the code into object code and skip the assembly and linking stages of the compile. This option is used quite often because it makes the compilation of multifile C&#43;&#43; programs faster and easier to manage. Object code files created by GCC have an <TT>.o</TT> extension by default.</P>

<P>The <TT>-S</TT> compiler option tells GCC to stop the compile after it has generated the assembler files for the C code. Assembler files generated by GCC have an <TT>.s</TT> extension by default. The <TT>-E</TT> option instructs the compiler to perform only the preprocessing compiler stage on the input files. When this option is used, the output from the preprocessor is sent to the standard output rather than being stored in a file.</P>

<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Debugging and Profiling Options</FONT></H3>

<P>GCC supports several debugging and profiling options. Of these options, the two that you are most likely to use for C&#43;&#43; programs are the <TT>-gstabs&#43;</TT> option and the <TT>-pg</TT> option.</P>

<P>The <TT>-gstabs&#43;</TT> option tells GCC to produce stabs format debugging information that the GNU debugger (<TT>gdb</TT>) can use to help you debug your program. For more information on debugging your C&#43;&#43; programs, see the &#147;Debugging C&#43;&#43; Applications&#148; section later in this chapter.</P>

<P>The <TT>-pg</TT> option tells GCC to add extra code to your program that will, when executed, generate profile information that can be used by the <TT>gprof</TT> program to display timing information about your program. For more information on <TT>gprof</TT>, refer to the &#147;<TT>gprof</TT>&#148; section in Chapter 26, &#147;Programming in C.&#148;</P>

<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">GCC C&#43;&#43; Specific Options</FONT></H4>

<P>The GCC options that control how a C&#43;&#43; program is compiled are listed in Table 27.1.

</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 27.1.</B> GCC options.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="40%" ALIGN="LEFT">Option

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

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>-fall-virtual</TT>

<TD>Treats all possible member functions as virtual. This applies to all functions except for constructor functions and new or delete member functions.

<TR>

<TD VALIGN="TOP"><TT>-fdollars-in-identifiers</TT>

<TD>Accepts &#36; in identifiers. You can also prohibit the use of &#36; in identifiers by using the <TT>-fno-dollars-in-identifiers</TT> option.

<TR>

<TD VALIGN="TOP"><TT>-felide-constructors</TT>

<TD>Tells the compiler to leave out constructors whenever possible.

<TR>

<TD VALIGN="TOP"><TT>-fenum-int-equiv</TT>

<TD>Permits implicit conversion of <TT>int</TT> to enumeration types.

<TR>

<TD VALIGN="TOP"><TT>-fexternal-templates</TT>

<TD>Produces smaller code for template declarations. This is done by having the compiler generate only a single copy of each template function where it is defined.

<TR>

<TD VALIGN="TOP"><TT>-fmemorize-lookups</TT>

<TD>Uses heuristics to compile faster. These heuristics are not enabled by default because they are effective only for certain input files.

<TR>

<TD VALIGN="TOP"><TT>-fno-strict-prototype</TT>

<TD>Treats a function declaration with no arguments the same way that C would treat it. This means that the compiler treats a function prototype that has no arguments as a function that will accept an unknown number of arguments.

<TR>

<TD VALIGN="TOP"><TT>-fno-null-objects</TT>

<TD>Assumes that objects reached through references are not null.

<TR>

<TD><TT>-fsave-memorized</TT>

<TD>Same as <TT>-fmemorize-lookups</TT>.

<TR>

<TD><TT>-fthis-is-variable</TT>

<TD>Permits assignment to &#147;this.&#148;

<TR>

<TD VALIGN="TOP"><TT>-nostdinc&#43;&#43;</TT>

<TD>Does not search for header files in the standard directories specific to C&#43;&#43;.

<TR>

<TD VALIGN="TOP"><TT>-traditional</TT>

<TD>This option has the same effect as <TT>-fthis-is-variable</TT>.

<TR>

<TD VALIGN="TOP"><TT>-fno-default-inline</TT>

<TD>Does not assume that functions defined within a class scope are inline functions.

<TR>

<TD VALIGN="TOP"><TT>-wenum-clash</TT>

<TD>Warns about conversion between different enumeration types.

<TR>

<TD VALIGN="TOP"><TT>-woverloaded-virtual</TT>

<TD>Warns when derived class function declaration may be an error in defining a virtual function. When you define a virtual function in a derived class, it must have the same signature as the function in the base class. This option tells the compiler to warn you if you have defined a function that has the same name and a different signature as a function that is defined in one of the base classes.

<TR>

<TD VALIGN="TOP"><TT>-wtemplate-debugging</TT>

<TD>If you are using templates, this option warns you if debugging is not yet available.

<TR>

<TD><TT>&#43;eN</TT>

<TD>Controls how virtual function definitions are used.

<TR>

<TD VALIGN="TOP"><TT>-gstabs&#43;</TT>

<TD>Tells the compiler to generate debugging information in stabs format, using GNU extensions understood only by the GNU debugger. The extra information produced by this option is necessary to ensure that <TT>gdb</TT> handles C&#43;&#43; programs properly.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="485-488.html">Previous</A></TD>

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

<TD><A HREF="491-494.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 + -