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

📄 439-444.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=439-444//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch09/435-438.html">Previous</A></TD>

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

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

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H2 ALIGN="CENTER"><FONT COLOR="#000077"><I>Section IV<BR>Linux Programming

</I></FONT></H2>

<P>The books ends with Chapter 10, an overview of Linux programming. In it you&#146;ll find explanations of Linux&#146;s programming tools (including the GNU C compiler) and its X Window programming tools.

</P>

<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 10<BR>Programming in Linux

</FONT></H2>

<P>This chapter covers:

</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;The GNU C compiler

<DD><B>&#149;</B>&nbsp;&nbsp;C programming

<DD><B>&#149;</B>&nbsp;&nbsp;The <B>cc</B> command

<DD><B>&#149;</B>&nbsp;&nbsp;Using <B>make</B>

<DD><B>&#149;</B>&nbsp;&nbsp;Programming under the X Window System

<DD><B>&#149;</B>&nbsp;&nbsp;Using LessTif to mimic Motif

<DD><B>&#149;</B>&nbsp;&nbsp;Using shared libraries

<DD><B>&#149;</B>&nbsp;&nbsp;Using <B>imake</B>

<DD><B>&#149;</B>&nbsp;&nbsp;Using Tcl/Tk

<DD><B>&#149;</B>&nbsp;&nbsp;A short introduction to using Perl

<DD><B>&#149;</B>&nbsp;&nbsp;Using <B>gawk</B>, the GNU Project version of <B>awk</B>

</DL>

<H3><A NAME="Heading2"></A><FONT COLOR="#000077">Programming under Linux</FONT></H3>

<P>This chapter is not going to turn you into an instant Linux and X Window programmer. We will, however, show you how to program in the Linux environment. We&#146;ll cover a lot of the odd things that you&#146;re supposed to know when programming on Linux, including where the X libraries are and some interesting tidbits about how Linux uses shared libraries.

</P>

<P>For the programmer, Linux offers all the freeware utilities and compilers you&#146;d expect for software that relies heavily on offerings from the Free Software Foundation. Starting with the GNU C compiler, you can develop C, C&#43;&#43;, Fortran (via <B>g77</B>), and Objective-C programs on your Linux system. In addition to these mainstream languages, Linux supports Tcl, Perl, and a host of other programming languages and second utilities. In addition, we&#146;ve thrown freeware called LessTif on the second accompanying CD-ROM, for those of you who want Motif compatibility but don&#146;t want to pay for commercial software.</P>

<P>Your main worry is whether you&#146;ve installed the proper disksets for your compiler and associated tools. (If you haven&#146;t heard of one before, a <I>compiler</I> is a tool that converts a program in text form into an executable Linux command.) Being programmers ourselves, we always recommend this; if you haven&#146;t, you can always go back and use the <B>setup</B> program to reinstall the proper disk sets.</P>

<P>If you&#146;re not a programmer, chances are that you&#146;ll be lost in much of this chapter. Even so, you&#146;ll find some interesting Linux utilities mentioned here. In addition, many free Linux programs come in source code-form only; you&#146;ll need to learn to compile them, so it&#146;s important to know about the process of compiling and linking C programs.</P>

<H3><A NAME="Heading3"></A><FONT COLOR="#000077">The Linux C Compiler: GNU CC</FONT></H3>

<P>The main C and C&#43;&#43; compiler on Linux is the GNU <B>gcc</B>. It is an all-encompassing program and can compile a number of programming languages: C, C&#43;&#43;, Fortran, and Objective-C. <B>Gcc</B>, or <B>cc</B>, which is linked to <B>gcc</B>, compiles C and C&#43;&#43; programs just like you&#146;d expect. The command-line parameters are all standard <B>cc</B> parameters in addition to the traditional <B>gcc</B> parameters. If you&#146;re used to programming on UNIX, you&#146;ll find Linux works as you&#146;d expect.</P>

<P>For those new to C programming, we&#146;ll provide a short introduction. If you&#146;re <I>really</I> new at this, you&#146;ll likely want to get a C programming book to help you out. Appendix A lists a few.</P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">C Programming</FONT></H4>

<P>C programs&#151;and in fact, most programs in general&#151;usually start in plain old text files. (Linux makes extensive use of simple text files, as you&#146;ve seen throughout this book.) These text files are created with text editors like <B>vi</B> or <B>emacs</B>. Once created, C programs must be compiled with a C compiler, <B>cc</B> or <B>gcc</B> (which are one and the same on Linux). This C compiler converts the text file, which the programmer wrote, into object, or machine, code for the Intel platform. Then, object modules (files of object code) are linked together to make an executable program, a brand new Linux command. Once the process is successfully completed, you can execute this program like any other command you type at the command line. Being able to create your own command is a neat thing.</P>

<P>In addition to creating C or C&#43;&#43; programs, you can use shell scripts or write code in a number of interpreted languages including Perl and Tcl, which we cover later in this chapter. From the plethora of Linux program-creation tools, you need to choose the appropriate tool for any given task.</P>

<P>The first step is identifying what types of files you&#146;re dealing with. Table 10.1 lists the most common Linux file types and their common file extensions.</P>

<TABLE WIDTH="100%"><CAPTION><B>Table 10.1</B> Program File Types

<TR>

<TH WIDTH="35%" ALIGN="LEFT">File Suffix

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

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD WIDTH="30%"><B>.a</B>

<TD WIDTH="70%">Library

<TR>

<TD><B>.c</B>

<TD>C program

<TR>

<TD><B>.C</B>

<TD>C&#43;&#43; file (note the uppercase <I>C</I>)

<TR>

<TD><B>.cc</B>

<TD>C&#43;&#43; file

<TR>

<TD><B>.cpp</B>

<TD>C&#43;&#43; file

<TR>

<TD><B>.cxx</B>

<TD>C&#43;&#43; file

<TR>

<TD><B>.c&#43;&#43;</B>

<TD>C&#43;&#43; file

<TR>

<TD><B>.f</B>

<TD>Fortran program

<TR>

<TD><B>.for</B>

<TD>Fortran program

<TR>

<TD><B>.h</B>

<TD>C or C&#43;&#43; include file

<TR>

<TD><B>.hxx</B>

<TD>C&#43;&#43; include file

<TR>

<TD><B>.o</B>

<TD>Object module (compiled from a <B>.c</B> file)

<TR>

<TD><B>.pl</B>

<TD>Perl script

<TR>

<TD><B>.pm</B>

<TD>Perl module script

<TR>

<TD><B>.s</B>

<TD>Assembly code

<TR>

<TD><B>.sa</B>

<TD>Shared library stubs linked with your program

<TR>

<TD><B>.so.<I>n</I></B>

<TD>Run-time shared library, version number is <I>n</I>

<TR>

<TD><B>.tcl</B>

<TD>Tcl script

<TR>

<TD><B>.tk</B>

<TD>Tcl script

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P>Most C programs are stored in one or more files that end with <I>.c</I>, for example, as <B>neatstuff.c</B> and <B>myprog.c</B>. When you compile a C file, the C compiler, <B>cc</B>, creates an object file, usually ending with <I>.o</I>. The linker (called <I>linkage editor</I> in Linux parlance), <B>ld</B>, then links the <I>.o</I> files to make an executable program. The default name for this program is <B>a.out</B>, although no one really uses <B>a.out</B> for their program names. Instead, programs have names like <B>ls</B>, <B>cp</B>, or <B>mv</B>. All of this is controlled by the <B>cc</B> command.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="../ch09/435-438.html">Previous</A></TD>

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

<TD><A HREF="444-447.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 + -