Date: Wed, 26 Jul 2006 01:09:10 +0800 From: chinsan <chinsan.tw@gmail.com> To: FreeBSD-gnats-submit@FreeBSD.org Cc: vanilla@FreeBSD.org Subject: docs/100812: [UPDATE] zh_TW: Update developers-handbook/tools to SVN#900 ! Message-ID: <20060725170359.83D102F068@smtp2.bc.hgc.com.tw> Resent-Message-ID: <200607251710.k6PHAFAl085266@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 100812 >Category: docs >Synopsis: [UPDATE] zh_TW: Update developers-handbook/tools to SVN#900 ! >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Tue Jul 25 17:10:15 GMT 2006 >Closed-Date: >Last-Modified: >Originator: chinsan >Release: FreeBSD 6.1-STABLE i386 >Organization: FreeBSD Taiwan >Environment: System: FreeBSD chinsan2.twbbs.org 6.1-STABLE FreeBSD 6.1-STABLE #1: Fri Jun 2 16:44:35 CST 2006 root@chinsan2.twbbs.org:/usr/obj/usr/src/sys/GENERIC i386 >Description: - Update developers-handbook/tools to SVN#900 ! patch URL http://chinsan2.twbbs.org/chinsan/zh_TW.Big5.20060725.developers-handbook3.diff - ChangeLog(Trac Timeline) https://opensvn.csie.org/traccgi/freebsddoc/timeline - Original translator: kevinblue Revised by chinsan >How-To-Repeat: >Fix: --- zh_TW.Big5.20060725.developers-handbook3.diff begins here --- --- zh_TW.Big5/books/developers-handbook.orig/tools/chapter.sgml Wed Jul 26 00:52:45 2006 +++ zh_TW.Big5/books/developers-handbook/tools/chapter.sgml Wed Jul 26 00:53:23 2006 @@ -1,7 +1,8 @@ <!-- The FreeBSD Documentation Project - $FreeBSD: doc/zh_TW.Big5/books/developers-handbook/tools/chapter.sgml,v 1.1 2006/06/17 10:22:44 vanilla Exp $ + $FreeBSD$ + Original revision: 1.46 --> <chapter id="tools"> @@ -19,127 +20,111 @@ </authorgroup> </chapterinfo> - <title>Programming Tools</title> - <sect1 id="tools-synopsis"><title>Synopsis</title> + <title>程式開發工具</title> + <sect1 id="tools-synopsis"><title>概敘</title> - <para>This chapter is an introduction to using some of the - programming tools supplied with FreeBSD, although much of it - will be applicable to many other versions of &unix;. It does - <emphasis>not</emphasis> attempt to describe coding in any - detail. Most of the chapter assumes little or no previous - programming knowledge, although it is hoped that most - programmers will find something of value in it.</para> + <para> + 本章將介紹如何使用一些 FreeBSD 所提供的程式開發工具(programing tools), + 本章所介紹的工具程式在其他版本的 &unix; 上也可使用, + 在此 <emphasis>並不會</emphasis> 嘗試描述寫程式時的每個細節, + 本章大部分篇幅都是假設你以前沒有或只有少數的寫程式經驗, + 不過,還是希望大多數的程式開發人員都能從中重新得到一些啟發。 + </para> </sect1> - <sect1 id="tools-intro"><title>Introduction</title> + <sect1 id="tools-intro"><title>簡介</title> - <para>FreeBSD offers an excellent development environment. - Compilers for C, C++, and Fortran and an assembler come with the - basic system, not to mention a Perl interpreter and classic &unix; - tools such as <command>sed</command> and <command>awk</command>. - If that is not enough, there are many more compilers and - interpreters in the Ports collection. FreeBSD is very - compatible with standards such as <acronym>&posix;</acronym> and - <acronym>ANSI</acronym> C, as well with its own BSD heritage, so - it is possible to write applications that will compile and run - with little or no modification on a wide range of - platforms.</para> - - <para>However, all this power can be rather overwhelming at first - if you have never written programs on a &unix; platform before. - This document aims to help you get up and running, without - getting too deeply into more advanced topics. The intention is - that this document should give you enough of the basics to be - able to make some sense of the documentation.</para> - - <para>Most of the document requires little or no knowledge of - programming, although it does assume a basic competence with - using &unix; and a willingness to learn!</para> + <para> + FreeBSD 提供一個非常棒的開發環境, + 比如說像是 C、C++、Fortran 和 assembler(組合語言)的編譯器(compiler), + 在 FreeBSD 中都已經包含在基本的系統中了 + 更別提 Perl 和其他標準 &unix; 工具,像是<command>sed</command> 以及 <command>awk</command>, + 如果你還是覺得不夠,FreeBSD在 Ports collection 中還提供其他的編譯器和直譯器(interpreter), + FreeBSD 相容許多標準,像是 <acronym>&posix;</acronym> 和 <acronym>ANSI</acronym> C, + 當然還有它所繼承的 BSD 傳統。 + 所以在 FreeBSD 上寫的程式不需修改或頂多稍微修改,就可以在許多平台上編譯、執行。 + </para> + + <para> + 無論如何,就算你從來沒在 &unix; 平台上寫過程式,也可以徹底感受到FreeBSD 令人無法抗拒的迷人魔力。 + 本章的目標就是協助你快速上手,而暫時不需深入太多進階主題, + 並且講解一些基礎概念,以讓你可以瞭解我們在講些什麼。 + </para> + + <para> + 本章內容並不要求你得有程式開發經驗,或者你只有一點點的經驗而已。 + 不過,我們假設你已經會 &unix; 系統的基本操作, + 而且更重要的是,請保持樂於學習的心態! + </para> </sect1> <sect1 id="tools-programming"> - <title>Introduction to Programming</title> + <title>Programming 概念</title> - <para>A program is a set of instructions that tell the computer to - do various things; sometimes the instruction it has to perform - depends on what happened when it performed a previous - instruction. This section gives an overview of the two main - ways in which you can give these instructions, or - <quote>commands</quote> as they are usually called. One way - uses an <firstterm>interpreter</firstterm>, the other a - <firstterm>compiler</firstterm>. As human languages are too - difficult for a computer to understand in an unambiguous way, - commands are usually written in one or other languages specially - designed for the purpose.</para> + <para> + 簡單的說,程式只是一堆指令的集合體;而這些指令是用來告訴電腦應該要作那些事情。 + 有時候,指令的執行取決於前一個指令的結果而定。 + 本章將會告訴你有 2 個主要的方法,讓你可以對電腦下達這些指示(instruction) 或 <quote>命令(commands)</quote>。 + 第一個方法就是 <firstterm>直譯器(interpreter)</firstterm>, + 而第二個方法是 <firstterm>編譯器(compiler)</firstterm>。 + 由於對於電腦而言,人類語言的語意過於模糊而太難理解, + 因此命令(commands)就常會以一種(或多種)程式語言寫成,用來指示電腦所要執行的特定動作為何。 + </para> <sect2> - <title>Interpreters</title> + <title>直譯器</title> - <para>With an interpreter, the language comes as an environment, - where you type in commands at a prompt and the environment - executes them for you. For more complicated programs, you can - type the commands into a file and get the interpreter to load - the file and execute the commands in it. If anything goes - wrong, many interpreters will drop you into a debugger to help - you track down the problem.</para> - - <para>The advantage of this is that you can see the results of - your commands immediately, and mistakes can be corrected - readily. The biggest disadvantage comes when you want to - share your programs with someone. They must have the same - interpreter, or you must have some way of giving it to them, - and they need to understand how to use it. Also users may not - appreciate being thrown into a debugger if they press the - wrong key! From a performance point of view, interpreters can - use up a lot of memory, and generally do not generate code as - efficiently as compilers.</para> - - <para>In my opinion, interpreted languages are the best way to - start if you have not done any programming before. This kind - of environment is typically found with languages like Lisp, - Smalltalk, Perl and Basic. It could also be argued that the - &unix; shell (<command>sh</command>, <command>csh</command>) is itself an - interpreter, and many people do in fact write shell - <quote>scripts</quote> to help with various - <quote>housekeeping</quote> tasks on their machine. Indeed, part - of the original &unix; philosophy was to provide lots of small - utility programs that could be linked together in shell - scripts to perform useful tasks.</para> + <para> + 使用直譯器時,所使用的程式語言就像變成一個會和你互動的環境。 + 當在命令提示列上打上命令時,直譯器會即時執行該命令。 + 在比較複雜的程式中,可以把所有想下達的命令統統輸入到某檔案裡面去, + 然後呼叫直譯器去讀取該檔案,並且執行你寫在這個檔案中的指令。 + 如果所下的指令有錯誤產生,大多數的直譯器會進入偵錯模式(debugger), + 並且顯示相關錯誤訊息,以便對程式除錯。 + </para> + + <para> + 這種方式好處在於:可以立刻看到指令的執行結果,以及錯誤也可迅速修正。 + 相對的,最大的壞處便是當你想把你寫的程式分享給其他人時,這些人必須要有跟你一樣的直譯器。 + 而且別忘了,他們也要會使用直譯器直譯程式才行。 + 當然使用者也不希望不小心按錯鍵,就進入偵錯模式而不知所措。 + 就執行效率而言,直譯器會使用到很多的記憶體, + 而且這類直譯式程式,通常並不會比編譯器所編譯的程式的更有效率。 + </para> + + <para> + 筆者個人認為,如果你之前沒有學過任何程式語言,最好先學學習直譯式語言(interpreted languages), + 像是 Lisp,Smalltalk,Perl 和 Basic 都是,&unix; 的 shell 像是 <command>sh</command> 和 <command>csh</command> + 它們本身就是直譯器,事實上,很多人都在它們自己機器上撰寫各式的 shell <quote>script</quote>, + 來順利完成各項 <quote>housekeeping(維護)</quote> 任務。 + &unix; 使用哲學之一就是提供大量的小工具, + 並使用 shell script 來組合運用這些小工具,以便工作更有效率。 </sect2> <sect2> - <title>Interpreters available with FreeBSD</title> + <title>FreeBSD 提供的直譯器</title> - <para>Here is a list of interpreters that are available from - the &os; Ports Collection, with a brief discussion of - some of the more popular interpreted languages.</para> - - <para>Instructions on how to get and install applications - from the Ports Collection can be found in the - <ulink url="&url.books.handbook;/ports-using.html"> - Ports section</ulink> of the handbook. + <para> + 下面這邊有份 &os; Ports Collection 所提供的直譯器清單,還有討論一些比較受歡迎的直譯式語言</para> + <para> + 至於如何使用 Ports Collection 安裝的說明,可參閱 FreeBSD Handbook 中的 + <ulink url="&url.books.handbook;/ports-using.html">Ports章節</ulink>。 <variablelist> <varlistentry> <term><acronym>BASIC</acronym></term> <listitem> - <para>Short for Beginner's All-purpose Symbolic - Instruction Code. Developed in the 1950s for teaching - University students to program and provided with every - self-respecting personal computer in the 1980s, - <acronym>BASIC</acronym> has been the first programming - language for many programmers. It is also the foundation - for Visual Basic.</para> - - <para>The Bywater Basic Interpreter can be found in the - Ports Collection as - <filename role="package">lang/bwbasic</filename> - and the Phil Cockroft's Basic Interpreter - (formerly Rabbit Basic) is available as - <filename role="package">lang/pbasic</filename>.</para> + <para>BASIC 是 Beginner's ALL-purpose Symbolic Instruction Code 的縮寫。 + BASIC 於 1950 年代開始發展,最初開發這套語言的目的是為了教導當時的大學學生如何寫程式。 + 到了 1980,<acronym>BASIC</acronym>已經是很多 programmer 第一個學習的程式語言了。 + 此外,BASIC 也是 Visual Basic 的基礎。</para> + + <para>FreeBSD Ports Collection 也有收錄相關的 BASIC 直譯器。 + Bywater Basic 直譯器放在 <filename role="package">lang/bwbasic</filename>。 + 而 Phil Cockroft's Basic 直譯器(早期也叫 Rabbit Basic)放在 <filename role="package">lang/pbasic</filename>。 </listitem> </varlistentry> @@ -147,29 +132,22 @@ <term>Lisp</term> <listitem> - <para>A language that was developed in the late 1950s as - an alternative to the <quote>number-crunching</quote> - languages that were popular at the time. Instead of - being based on numbers, Lisp is based on lists; in fact - the name is short for <quote>List Processing</quote>. - Very popular in <acronym>AI</acronym> (Artificial Intelligence) - circles.</para> - - <para>Lisp is an extremely powerful and sophisticated - language, but can be rather large and unwieldy.</para> - - <para>Various implementations of Lisp that can run on &unix; - systems are available in the Ports Collection for &os;. - GNU Common Lisp can be found as - <filename role="package">lang/gcl</filename>. CLISP - by Bruno Haible and Michael Stoll is available as - <filename role="package">lang/clisp</filename>. - For CMUCL, which includes a highly-optimizing compiler too, or - simpler Lisp implementations like SLisp, which implements most - of the Common Lisp constructs in a few hundred lines of C code, - <filename role="package">lang/cmucl</filename> and - <filename role="package">lang/slisp</filename> are available - respectively.</para> + <para>LISP 是在 1950 年代開始發展的一個直譯式語言,而且 LISP 就是一種 + <quote>number-crunching</quote> languages(迅速進行大量運算的程式語言),在當時算是一個普遍的程式語言。 + LISP 的表達不是基於數字(numbers),而是基於表(lists)。 + 而最能表示出 LISP 特色的地方就在於: LISP 是 <quote>List Processing</quote> 的縮寫。 + 在<acronym>人工智慧(Artificial Intelligence, AI)</acronym>領域上 LISP 的各式應用非常普遍。</para> + + <para>LISP 是非常強悍且複雜的程式語言,但是缺點是程式碼會非常大而且難以操作。</para> + + <para>絕大部分的 LISP 直譯器都可以在 &unix; 系統上運作,當然 &os; 的 Ports Collection 也有收錄。 + GNU Common Lisp 收錄在 <filename role="package">lang/gcl</filename>, + Bruno Haible 和 Michael Stoll 的 CLISP 收錄在 <filename role="package">lang/clisp</filename> + ,此外 CMUCL(包含一個已經最佳化的編譯器), + 以及其他簡化版的 LISP 直譯器(比如以 C 語言寫的 SLisp,只用幾百行程式碼就實作大多數 Common Lisp 的功能) + 則是分別收錄在 <filename role="package">lang/cmucl</filename> 以及 + <filename role="package">lang/slisp</filename>。 + </para> </listitem> </varlistentry> @@ -177,14 +155,11 @@ <term>Perl</term> <listitem> - <para>Very popular with system administrators for writing - scripts; also often used on World Wide Web servers for - writing <acronym>CGI</acronym> scripts.</para> - - <para>Perl is available in the Ports Collection as - <filename role="package">lang/perl5</filename> for all - &os; releases, and is installed as <command>/usr/bin/perl</command> - in the base system 4.X releases.</para> + <para>對系統管理者而言,最愛用 perl 來撰寫 scripts 以管理主機, + 同時也經常用來寫 WWW 主機上的 <acronym>CGI</acronym> Script 程式。</para> + + <para>Perl 在 Ports Collection 內的 <filename role="package">lang/perl5</filename>。 + 而 &os; 4.X 則是把 Perl 裝在 <command>/usr/bin/perl</command>。</para> </listitem> </varlistentry> @@ -192,19 +167,15 @@ <term>Scheme</term> <listitem> - <para>A dialect of Lisp that is rather more compact and - cleaner than Common Lisp. Popular in Universities as it - is simple enough to teach to undergraduates as a first - language, while it has a high enough level of - abstraction to be used in research work.</para> - - <para>Scheme is available from the Ports Collection as - <filename role="package">lang/elk</filename> for the - Elk Scheme Interpreter. The MIT Scheme Interpreter - can be found in - <filename role="package">lang/mit-scheme</filename> - and the SCM Scheme Interpreter in - <filename role="package">lang/scm</filename>.</para> + <para>Scheme 是 LISP 的另一分支,Scheme 的特點就是比 Common LISP 還要簡潔有力。 + 由於 Scheme 簡單,所以很多大學拿來當作第一堂程式語言教學教材。 + 而且對於研究人員來說也可以快速的開發他們所需要的程式。 + </para> + + <para>Scheme 收錄在 <filename role="package">lang/elk</filename>, + Elk Scheme 直譯器(由麻省理工學院所發展的 Scheme 直譯器)收錄在 + <filename role="package">lang/mit-scheme</filename>, + SCM Scheme Interpreter 收錄在 <filename role="package">lang/scm</filename>。</para> </listitem> </varlistentry> @@ -212,11 +183,9 @@ <term>Icon</term> <listitem> - <para>Icon is a high-level language with extensive - facilities for processing strings and structures. - The version of Icon for &os; can be found in the - Ports Collection as - <filename role="package">lang/icon</filename>.</para> + <para>Icon 屬高階程式語言,Icon 具有強大的字串(String)和結構(Structure)處理能力。 + &os; Ports Collection 所收錄的 Icon 直譯器版本則是放在 + <filename role="package">lang/icon</filename>。</para> </listitem> </varlistentry> @@ -224,16 +193,11 @@ <term>Logo</term> <listitem> - <para>Logo is a language that is easy to learn, and has - been used as an introductory programming language in - various courses. It is an excellent tool to work with - when teaching programming in small ages, as it makes the - creation of elaborate geometric shapes an easy task even - for very small children.</para> - - <para>The lastest version of Logo for &os; is available from - the Ports Collection in - <filename role="package">lang/logo</filename>.</para> + <para>Logo 是種容易學習的程式語言,最常在一些教學課程中被拿來當作開頭範例。 + 如果要給小朋友開始上程式語言課的話,Logo 是相當不錯的選擇。 + 因為,即使對小朋友來說,要用 Logo 來秀出複雜多邊形圖形是相當輕鬆容易的。</para> + + <para>Logo 在 &os; Ports Collection 的最新版則是放在 <filename role="package">lang/logo</filename>。</para> </listitem> </varlistentry> @@ -241,17 +205,13 @@ <term>Python</term> <listitem> - <para>Python is an Object-Oriented, interpreted language. - Its advocates argue that it is one of the best languages - to start programming with, since it is relatively easy - to start with, but is not limited in comparison to other - popular interpreted languages that are used for the - development of large, complex applications (Perl and - Tcl are two other languages that are popular for such tasks).</para> - - <para>The latest version of Python is available from the - Ports Collection in - <filename role="package">lang/python</filename>.</para> + <para>Python 是物件導向的直譯式語言, + Python 的擁護者總是宣稱 Python 是最好入門的程式語言。 + 雖然 Python 可以很簡單的開始,但是不代表它就會輸給其他直譯式語言(像是 Perl 和 Tcl), + 事實證明 Python 也可以拿來開發大型、複雜的應用程式。 + </para> + + <para>&os; Ports Collection 收錄在 <filename role="package">lang/python</filename>。</para> </listitem> </varlistentry> @@ -259,14 +219,11 @@ <term>Ruby</term> <listitem> - <para>Ruby is an interpreter, pure object-oriented programming - language. It has become widely popular because of its easy - to understand syntax, flexibility when writing code, and the - ability to easily develop and maintain large, complex - programs.</para> + <para>Ruby 是純物件導向的直譯式語言。 + Ruby 目前非常流行,原因在於他易懂的程式語法結構,在撰寫程式時的彈性, + 以及天生具有輕易的發展維護大型專案的能力。</para> - <para>Ruby is available from the Ports Collection as - <filename role="package">lang/ruby18</filename>.</para> + <para>&os; Ports Collection 收錄在 <filename role="package">lang/ruby8</filename>。</para> </listitem> </varlistentry> @@ -274,70 +231,50 @@ <term>Tcl and Tk</term> <listitem> - <para>Tcl is an embeddable, interpreted language, that has - become widely used and became popular mostly because of its portability to many - platforms. It can be used both for quickly writing - small, prototype applications, or (when combined with - Tk, a GUI toolkit) fully-fledged, featureful - programs.</para> - - <para>Various versions of Tcl are available as ports - for &os;. The latest version, Tcl 8.4, can be found in - <filename role="package">lang/tcl84</filename>.</para> + <para>Tcl 是內嵌式的直譯式語言,讓 Tcl 可以如此廣泛運用的原因是 Tcl 的移植性。 + Tcl 也可以快速發展一個簡單但是具有雛型的程式或者具有完整功能的程式。</para> + + <para>Tcl 許多的版本都可在 &os; 上運作,而最新的 Tcl 版本為 Tcl 8.4, + &os; Ports Collection 收錄在 <filename role="package">lang/tcl84</filename>。</para> </listitem> </varlistentry> </variablelist> </sect2> <sect2> - <title>Compilers</title> - - <para>Compilers are rather different. First of all, you write - your code in a file (or files) using an editor. You then run - the compiler and see if it accepts your program. If it did - not compile, grit your teeth and go back to the editor; if it - did compile and gave you a program, you can run it either at a - shell command prompt or in a debugger to see if it works - properly. + <title>編譯器</title> + <para>編譯器和直譯器兩者相比的話,有些不同,首先就是必須先把程式碼統統寫入到檔案裡面, + 然後必須執行編譯器來試著編譯程式,如果編譯器不接受所寫的程式,那就必須一直修改程式, + 直到編譯器接受且把你的程式編譯成執行檔。 + 此外,也可以在提示命令列,或在除錯器中執行你編譯好的程式看看它是否可以運作。 <footnote> - <para>If you run it in the shell, you may get a core - dump.</para> + <para>如果在提示命令列下執行,那麼有可能會產生 core dump。</para> </footnote></para> - <para>Obviously, this is not quite as direct as using an - interpreter. However it allows you to do a lot of things - which are very difficult or even impossible with an - interpreter, such as writing code which interacts closely with - the operating system—or even writing your own operating - system! It is also useful if you need to write very efficient - code, as the compiler can take its time and optimize the code, - which would not be acceptable in an interpreter. Moreover, - distributing a program written for a compiler is usually more - straightforward than one written for an interpreter—you - can just give them a copy of the executable, assuming they - have the same operating system as you.</para> - - <para>Compiled languages include Pascal, C and C++. C and C++ - are rather unforgiving languages, and best suited to more - experienced programmers; Pascal, on the other hand, was - designed as an educational language, and is quite a good - language to start with. FreeBSD does not include Pascal - support in the base system, but both GNU Pascal Compiler (GPC) - and the Free Pascal Compiler - are available in the ports collection as - <filename role="package">lang/gpc</filename> and - <filename role="package">lang/fpc</filename>.</para> - - <para>As the edit-compile-run-debug cycle is rather tedious when - using separate programs, many commercial compiler makers have - produced Integrated Development Environments - (<acronym>IDE</acronym>s for short). FreeBSD does not include - an IDE in the base system, but <filename role="package">devel/kdevelop</filename> is - available in the ports tree and many use - <application>Emacs</application> for this purpose. Using - <application>Emacs</application> as an IDE is discussed in - <xref linkend="emacs">.</para> + <para>很明顯的,使用編譯器並不像直譯器般可以馬上得到結果。 + 不管如何,編譯器允許你作很多直譯器不可能或者是很難達到的事情。 + 例如:撰寫和作業系統密切互動的程式,甚至是你自己寫的作業系統! + 當你想要寫出高效率的程式時,編譯器便派上用場了。 + 編譯器可以在編譯時順便最佳化你的程式,但是直譯器卻不行。 + 而編譯器與直譯器最大的差別在於:當你想把你寫好的程式拿到另外一台機器上跑時, + 你只要將編譯器編譯出來的可執行檔,拿到新機器上便可以執行, + 而直譯器則必須要求新機器上,必須要有跟另一台機器上相同的直譯器, + 才能組譯執行你的程式! + </para> + + <para>編譯式的程式語言包含 Pascal、C 和 C++, + C 和 C++ 不是一個親和力十足的語言,但是很適合具有經驗的 Programmer。 + Pascal 其實是一個設計用來教學用的程式語言,而且也很適合用來入門, + &os; 預設並沒有把 Pascal 整合進 base system 中, + 但是 GNU Pascal Compiler 和 Free Pascal Compiler 都可分別在 + <filename role="package">lang/gpc</filename> 和 <filename role="package">lang/fpc</filename> 中找到。</para> + + <para>如果你用不同的程式來寫編譯式程式,那麼不斷地編輯-編譯-執行-除錯的這個循環肯定會很煩人, + 為了更簡化、方便程式開發流程,很多商業編譯器廠商開始發展所謂的 <acronym>IDE</acronym>(Integrated Development Environments) 開發環境, + FreeBSD 預設並沒有把 IDE 整合進 base system 中,但是你可透過 <filename role="package">devel/kdevelop</filename> 安裝 kdevelop + 或使用 <application>Emacs</application> 來體驗 IDE 開發環境。 + 在後面的 <xref linkend="emacs"> 專題將介紹,如何以 <application>Emacs</application> 來作為 IDE 開發環境。</para> </sect2> @@ -345,127 +282,95 @@ <sect1 id="tools-compiling"> - <title>Compiling with <command>cc</command></title> + <title>用 <command>cc</command> 來編譯程式</title> + + <para>本章範例只有針對 GNU C compiler 和 GNU C++ compiler 作說明, + 這兩個在 FreeBSD base system 中就有了, + 直接打 <command>cc</command> 或 <command>gcc</command> 就可以執行。 + 至於,如何用直譯器產生程式的說明,通常可在直譯器的文件或線上文件找到說明,因此不再贅述。</para> - <para>This section deals only with the GNU compiler for C and C++, - since that comes with the base FreeBSD system. It can be - invoked by either <command>cc</command> or <command>gcc</command>. The - details of producing a program with an interpreter vary - considerably between interpreters, and are usually well covered - in the documentation and on-line help for the - interpreter.</para> - - <para>Once you have written your masterpiece, the next step is to - convert it into something that will (hopefully!) run on FreeBSD. - This usually involves several steps, each of which is done by a - separate program.</para> + <para>當你寫完你的傑作後,接下來便是讓這個程式可以在 FreeBSD 上執行, + 通常這些要一些步驟才能完成,有些步驟則需要不同程式來完成。</para> <procedure> <step> - <para>Pre-process your source code to remove comments and do - other tricks like expanding macros in C.</para> + <para>預先處理(Pre-process)你的程式碼,移除程式內的註解,和其他技巧, + 像是 expanding(擴大) C 的 marco。</para> </step> <step> - <para>Check the syntax of your code to see if you have obeyed - the rules of the language. If you have not, it will - complain!</para> + <para>確認你的程式語法是否確實遵照 C/C++ 的規定,如果沒有符合的話,編譯器會出現警告。</para> </step> <step> - <para>Convert the source code into assembly - language—this is very close to machine code, but still - understandable by humans. Allegedly. - + <para>將原始碼轉成組合語言 — 它跟機器語言(machine code)非常相近,但仍在人類可理解的範圍內(據說應該是這樣)。 <footnote> - <para>To be strictly accurate, <command>cc</command> converts the - source code into its own, machine-independent - <firstterm>p-code</firstterm> instead of assembly language at - this stage.</para> + <para>嚴格說起來,在這個階段 <command>cc</command> 並不是真的把原始程式轉成組合語言, + 而是轉為 machine-independent 的 <firstterm>p-code</firstterm>。</para> </footnote></para> </step> <step> - <para>Convert the assembly language into machine - code—yep, we are talking bits and bytes, ones and - zeros here.</para> + <para>把組合語言轉成機器語言 — 是的,這裡說的機器語言就是常提到的 bit 和 byte,也就是 1 和 0。</para> </step> <step> - <para>Check that you have used things like functions and - global variables in a consistent way. For example, if you - have called a non-existent function, it will - complain.</para> + <para>確認程式中用到的函式呼叫、全域變數是否正確,舉例來說:如若呼叫了不存在的函式,編譯器會顯示警告。</para> </step> <step> - <para>If you are trying to produce an executable from several - source code files, work out how to fit them all - together.</para> + <para>如果程式是由程式碼檔案來編譯,編譯器會整合起來。</para> </step> <step> - <para>Work out how to produce something that the system's - run-time loader will be able to load into memory and - run.</para> + <para>編譯器會負責產生東西,讓系統上的 run-time loader 可以把程式載入記憶體內執行。</para> </step> <step> - <para>Finally, write the executable on the filesystem.</para> + <para>最後會把編譯完的執行檔存在硬碟上。</para> </step> </procedure> - <para>The word <firstterm>compiling</firstterm> is often used to refer to - just steps 1 to 4—the others are referred to as - <firstterm>linking</firstterm>. Sometimes step 1 is referred to as - <firstterm>pre-processing</firstterm> and steps 3-4 as - <firstterm>assembling</firstterm>.</para> - - <para>Fortunately, almost all this detail is hidden from you, as - <command>cc</command> is a front end that manages calling all these - programs with the right arguments for you; simply typing</para> - + <para>通常 <firstterm>編譯(compiling)</firstterm> 是指第 1 到第 4 個步驟。 + — 其他步驟則稱為 <firstterm>連結(linking)</firstterm>, + 有時候步驟 1 也可以是指 <firstterm>預先處理(pre-processing)</firstterm>, + 而步驟 3 到步驟 4 則是 <firstterm>組譯(assembling)</firstterm>。</para> + + <para>幸運的是,你可以不用理會以上細節,編譯器都會自動完成。 + 因為 <command>cc</command> 只是是個前端程式(front end),它會依照正確的參數來呼叫相關程式幫你處理。 + 只需打: <screen>&prompt.user; <userinput>cc foobar.c</userinput></screen> - <para>will cause <filename>foobar.c</filename> to be compiled by all the - steps above. If you have more than one file to compile, just do - something like</para> + <para>上述指令會把 <filename>foobar.c</filename> 開始編譯,並完成上述動作。 + 如果你有許多檔案需要編譯,那請打類似下列指令即可:</para> <screen>&prompt.user; <userinput>cc foo.c bar.c</userinput></screen> - <para>Note that the syntax checking is just that—checking - the syntax. It will not check for any logical mistakes you may - have made, like putting the program into an infinite loop, or - using a bubble sort when you meant to use a binary - sort. - + <para>記住語法錯誤檢查就是 — 純粹檢查語法錯誤與否, + 而不會幫你檢測任何邏輯錯誤,比如:無限迴圈,或是排序方式想用 binary sort 卻弄成 bubble sort。 <footnote> - <para>In case you did not know, a binary sort is an efficient - way of sorting things into order and a bubble sort - is not.</para> + <para>剛所說的 binary sort 和 bubble sort 問題, + 在已排序好的序列中,binary sort 搜索效率會比 bubble sort 好。</para> </footnote></para> - <para>There are lots and lots of options for <command>cc</command>, which - are all in the manual page. Here are a few of the most important - ones, with examples of how to use them.</para> + <para><command>cc</command> 有非常多的選項,都可透過線上手冊來查。 + 下面只提一些必要且重要的選項,以作為例子。</para> <variablelist> <varlistentry> - <term><option>-o <replaceable>filename</replaceable></option></term> + <term><option>-o <replaceable>檔名</replaceable></option></term> <listitem> - <para>The output name of the file. If you do not use this - option, <command>cc</command> will produce an executable called - <filename>a.out</filename>. + <para><option>-o</option> 編譯後的執行檔檔名,如果沒有使用這選項的話, + 編譯好的程式預設檔名將會是 <filename>a.out</filename> <footnote> - <para>The reasons for this are buried in the mists of - history.</para> + <para>至於 <option>-o</option> 的原因,則是一團歷史迷霧了。</para> </footnote></para> <informalexample> - <screen>&prompt.user; <userinput>cc foobar.c</userinput> <lineannotation>executable is <filename>a.out</filename></lineannotation> -&prompt.user; <userinput>cc -o foobar foobar.c</userinput> <lineannotation>executable is <filename>foobar</filename></lineannotation> + <screen>&prompt.user; <userinput>cc foobar.c</userinput> <lineannotation>執行檔就是 <filename>a.out</filename></lineannotation> +&prompt.user; <userinput>cc -o foobar foobar.c</userinput> <lineannotation>執行檔就是 <filename>foobar</filename></lineannotation> </screen> </informalexample> </listitem> @@ -475,19 +380,17 @@ <term><option>-c</option></term> <listitem> - <para>Just compile the file, do not link it. Useful for toy - programs where you just want to check the syntax, or if - you are using a <filename>Makefile</filename>.</para> + <para>使用 <option>-c</option> 時,只會編譯原始碼,而不作連結(linking)。 + 當只想確認語法是否正確或使用 Makefile 來編譯程式時,這個選項非常有用。</para> <informalexample> - <screen>&prompt.user; <userinput>cc -c foobar.c</userinput> + <screen> + &prompt.user; <userinput>cc -c foobar.c</userinput> </screen> </informalexample> - <para>This will produce an <firstterm>object file</firstterm> (not an - executable) called <filename>foobar.o</filename>. This - can be linked together with other object files into an - executable.</para> + <para>這會產生叫做 <filename>foobar</filename> 的 <firstterm>object file</firstterm>(非執行檔)。 + 這檔可以與其他的 object file 連結在一起,而成執行檔。</para> </listitem> </varlistentry> @@ -495,33 +398,25 @@ <term><option>-g</option></term> <listitem> - <para>Create a debug version of the executable. This makes - the compiler put information into the executable about - which line of which source file corresponds to which - function call. A debugger can use this information to show - the source code as you step through the program, which is - <emphasis>very</emphasis> useful; the disadvantage is that - all this extra information makes the program much bigger. - Normally, you compile with <option>-g</option> while you - are developing a program and then compile a <quote>release - version</quote> without <option>-g</option> when you are - satisfied it works properly.</para> + <para> + <option>-g</option> 將會把一些給 gdb 用的除錯訊息包進去執行檔裡面,所謂的除錯訊息例如: + 程式在第幾行出錯、那個程式第幾行做什麼函式呼叫等等。除錯資訊<emphasis>非常</emphasis>好用。 + 但缺點就是:對於程式來說,額外的除錯訊息會讓編譯出來的程式比較肥些。 + <option>-g</option> 的適用時機在於:當程式還在開發時使用就好, + 而當你要釋出你的 <quote>發行版本(release version)</quote> + 或者確認程式可運作正常的話,就不必用 <option>-g</option> 這選項了。</para> <informalexample> <screen>&prompt.user; <userinput>cc -g foobar.c</userinput> </screen> </informalexample> - <para>This will produce a debug version of the - program. - + <para>這動作會產生有含除錯訊息的執行檔。 <footnote> - <para>Note, we did not use the <option>-o</option> flag - to specify the executable name, so we will get an - executable called <filename>a.out</filename>. - Producing a debug version called - <filename>foobar</filename> is left as an exercise for - the reader!</para> + <para>請注意,因為上例沒用 <option>-o</option> 以指定執行檔名稱, + 所以執行檔會是 <filename>a.out</filename> 這檔。 + 那麼,要如何產生 <filename>foobar</filename> 的執行檔並內含除錯訊息, + 這就留待看倌們練習一下囉。</para> </footnote></para> </listitem> </varlistentry> @@ -530,45 +425,38 @@ <term><option>-O</option></term> <listitem> - <para>Create an optimized version of the executable. The - compiler performs various clever tricks to try to produce - an executable that runs faster than normal. You can add a - number after the <option>-O</option> to specify a higher - level of optimization, but this often exposes bugs in the - compiler's optimizer. For instance, the version of - <command>cc</command> that comes with the 2.1.0 release of - FreeBSD is known to produce bad code with the - <option>-O2</option> option in some circumstances.</para> + <para><option>-O</option> 會產生最佳化的執行檔, + 編譯器會使用一些技巧,來讓程式可以跑的比未經最佳化的程式還快, + 你可以在大寫 O 後面加上數字來指明你想要的最佳化層級。 + 但是最佳化還是會有一些錯誤,舉例來說在當在 FreeBSD 2.10 release 中使用 <command>cc</command> + 並且指定 <option>-O2</option> 時,在某些情形下會產生錯誤的執行檔。</para> - <para>Optimization is usually only turned on when compiling - a release version.</para> + <para>只有當要釋出發行版本、或者加速程式時,才需要使用最佳化選項。 + </para> <informalexample> <screen>&prompt.user; <userinput>cc -O -o foobar foobar.c</userinput> </screen> </informalexample> - <para>This will produce an optimized version of - <filename>foobar</filename>.</para> + <para>這會產生 <filename>foobar</filename> 執行檔的最佳化版本。</para> </listitem> </varlistentry> </variablelist> - <para>The following three flags will force <command>cc</command> - to check that your code complies to the relevant international - standard, often referred to as the <acronym>ANSI</acronym> - standard, though strictly speaking it is an - <acronym>ISO</acronym> standard.</para> + <para> + 以下三個參數將會強迫 <command>cc</command> 確認程式碼是否符合一些國際標準的規範, + 也就是通常說的 <acronym>ANSI</acronym> 標準, + 而 <acronym>ANSI</acronym> 嚴格來講屬 <acronym>ISO</acronym> 標準。 + </para> <variablelist> <varlistentry> <term><option>-Wall</option></term> <listitem> - <para>Enable all the warnings which the authors of - <command>cc</command> believe are worthwhile. Despite the - name, it will not enable all the warnings - <command>cc</command> is capable of.</para> + <para><option>-Wall</option> 顯示 <command>cc</command> 維護者所認為值得注意的所有警告訊息。 + 不過這名字可能會造成誤解,事實上它並未完全顯示 <command>cc</command> 所能注意到的各項警告訊息。</para> </listitem> </varlistentry> @@ -576,11 +464,8 @@ <term><option>-ansi</option></term> <listitem> - <para>Turn off most, but not all, of the - non-<acronym>ANSI</acronym> C features provided by - <command>cc</command>. Despite the name, it does not - guarantee strictly that your code will comply to the - standard.</para> + <para><option>-ansi</option> 關閉 <command>cc</command> 特有的某些特殊非 ANSI C 標準功能。 + 不過這名字可能會造成誤解,事實上它並不保證你的程式會完全符合 ANSI 標準。</para> </listitem> </varlistentry> @@ -588,74 +473,57 @@ <term><option>-pedantic</option></term> <listitem> - <para>Turn off <emphasis>all</emphasis> - <command>cc</command>'s non-<acronym>ANSI</acronym> C - features.</para> + <para>全面關閉 <command>cc</command> 所特有的非 <acronym>ANSI</acronym> C 標準功能。</para> </listitem> </varlistentry> </variablelist> - <para>Without these flags, <command>cc</command> will allow you to - use some of its non-standard extensions to the standard. Some - of these are very useful, but will not work with other - compilers—in fact, one of the main aims of the standard is - to allow people to write code that will work with any compiler - on any system. This is known as <firstterm>portable - code</firstterm>.</para> - - <para>Generally, you should try to make your code as portable as - possible, as otherwise you may have to completely rewrite the - program later to get it to work somewhere else—and who - knows what you may be using in a few years time?</para> + <para>除了這些參數,<command>cc</command> 還允許你使用一些額外的參數取代標準參數,有些額外參數非常有用, + 但是實際上並不是所有的編譯器都有提供這些參數。 + 照標準來寫程式的最主要目的就是,希望你寫出來的程式可以在所有編譯器上編譯、執行無誤, + 當程式可以達成上述目的時,就稱為 <firstterm>portable code(移植性良好的程式碼)</firstterm>。</para> + + <para>一般來說,在撰寫程式時就應要注意『移植性』。 + 否則。當想把程式拿到另外一台機器上跑的時候,就可能得需要重寫程式。</para> <informalexample> <screen>&prompt.user; <userinput>cc -Wall -ansi -pedantic -o foobar foobar.c</userinput></screen> </informalexample> - <para>This will produce an executable <filename>foobar</filename> - after checking <filename>foobar.c</filename> for standard - compliance.</para> + <para>上述指令會確認 <filename>foobar.c</filename> 內的語法是否符合標準, + 並且產生名為 <filename>foobar</filename> 的執行檔。</para> <variablelist> <varlistentry> <term><option>-l<replaceable>library</replaceable></option></term> <listitem> - <para>Specify a function library to be used at link time.</para> + <para>告訴 gcc 在連結(linking)程式時你需要用到的函式庫名稱。</para> - <para>The most common example of this is when compiling a - program that uses some of the mathematical functions in C. - Unlike most other platforms, these are in a separate - library from the standard C one and you have to tell the - compiler to add it.</para> - - <para>The rule is that if the library is called - <filename>lib<replaceable>something</replaceable>.a</filename>, - you give <command>cc</command> the argument - <option>-l<replaceable>something</replaceable></option>. - For example, the math library is - <filename>libm.a</filename>, so you give - <command>cc</command> the argument <option>-lm</option>. - A common <quote>gotcha</quote> with the math library is - that it has to be the last library on the command - line.</para> + <para>最常見的情況就是,當你在程式中使用了 C 數學函式庫, + 跟其他作業平台不一樣的是,這些數學函式都不在標準函式庫(library)中, + 因此編譯器並不知道這函式庫名稱,你必須告訴編譯器要加上它才行。</para> + + <para>這規則很簡單,如果有個函式庫叫做 <filename>lib<replaceable>something</replaceable>/a</filename>, + 就必須在編譯時加上參數 <option>-l<replaceable>something</replaceable></option> 才行。 + 舉例來說,數學函式庫叫做 <filename>libm.a</filename>, + 所以你必須給 <command>cc</command> 的參數就是 <option>-lm</option>。 + 一般情況下,通常會把這參數必須放在指令的最後。 + </para> <informalexample> <screen>&prompt.user; <userinput>cc -o foobar foobar.c -lm</userinput> </screen> </informalexample> - <para>This will link the math library functions into - <filename>foobar</filename>.</para> + <para>上面這指令會讓 gcc 跟數學函式庫作連結,以便你的程式可以呼叫函式庫內含的數學函式。</para> - <para>If you are compiling C++ code, you need to add - <option>-lg++</option>, or <option>-lstdc++</option> if - you are using FreeBSD 2.2 or later, to the command line - argument to link the C++ library functions. - Alternatively, you can run <command>c++</command> instead - of <command>cc</command>, which does this for you. - <command>c++</command> can also be invoked as - <command>g++</command> on FreeBSD.</para> + <para>如果你正在編譯的程式是 C++ 程式碼,你還必須額外指定 <option>-lg++</option> 或者是 + <option>-lstdc++</option>。 + 如果你的 FreeBSD 是 2.2(含)以後版本, + 你可以用指令 <command>c++</command> 來取代 <command>cc</command>。 + 在 FreeBSD 上 <command>c++</command> 也可以用 <command>g++</command> 取代。 + </para> <informalexample> <screen>&prompt.user; <userinput>cc -o foobar foobar.cc -lg++</userinput> <lineannotation>For FreeBSD 2.1.6 and earlier</lineannotation> --- zh_TW.Big5.20060725.developers-handbook3.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060725170359.83D102F068>