📄 programming-concepts-techniques.sgml
字号:
different role. </PARA>
<SECT1 id="component-repo">
<TITLE>Component Repository</TITLE>
<PARA>The <productname>eCos</productname> <FIRSTTERM>component repository</FIRSTTERM>
contains directories for all the packages that are shipped
with <productname>eCos</productname> or provided by third parties.</PARA>
<PARA>The component repository should not be modified as part of
application development. </PARA>
<!--
<para>
XXXXX We may want to change this picture XXXXX
</para>
-->
<FIGURE>
<TITLE>Component repository</TITLE>
<GRAPHIC ENTITYREF="graphic30"></GRAPHIC>
</FIGURE>
<SECT2>
<TITLE>Purpose</TITLE>
<PARA>The component repository is the master copy of source code
for all system and third party components. It also contains some
files needed to administer and build the system, such as <command>ecosadmin.tcl</command>.</PARA>
</SECT2>
<SECT2>
<TITLE>How is it modified?</TITLE>
<PARA>You modify it by importing new versions of packages from a
distribution or removing existing packages. These activities are
undertaken using the <productname>eCos</productname> <application>Package Administration Tool</application>.</PARA>
</SECT2>
<SECT2>
<TITLE>When is it edited manually?</TITLE>
<PARA>Files in the component repository should only be edited manually
as determined by the component maintainer.</PARA>
</SECT2>
<SECT2>
<TITLE>User Applications</TITLE>
<PARA>User application source code should <EMPHASIS>not</EMPHASIS> go
into the component repository.</PARA>
</SECT2>
<SECT2>
<TITLE>Examples of files in this hierarchy:</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/doc/ref/ecos-ref.html</FILENAME></TERM>
<LISTITEM>
<PARA>The top level HTML file for the
<citetitle><PRODUCTNAME>eCos</PRODUCTNAME> Reference
Manual</citetitle>. </PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/prebuilt/pid/tests/kernel/<replaceable>&Version;</replaceable>/tests/thread_gdb.exe</FILENAME></TERM>
<LISTITEM>
<PARA></PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/prebuilt/linux/tests/kernel/<replaceable>&Version;</replaceable>/tests/thread_gdb.exe</FILENAME></TERM>
<LISTITEM>
<PARA>Pre-built tests for the supported platforms, and
the synthetic Linux target.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/examples/twothreads.c</FILENAME></TERM>
<LISTITEM>
<PARA>One of the example programs.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/ecosadmin.tcl</FILENAME></TERM>
<LISTITEM>
<para>The Tcl program which is used to import new versions of packages
from a distribution or remove existing packages.</para>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/packages/language/c/libm/<replaceable>&Version;</replaceable>/src/double/portable-api/s_tanh.c</FILENAME></TERM>
<LISTITEM>
<para>Implementation of the hyperbolic tangent function in the standard
math library.</para>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/pkgconf/rules.mak</FILENAME></TERM>
<LISTITEM>
<para>A file with <command>make</command> rules, used
by the <FILENAME>makefile</FILENAME>.</para>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECT2>
</SECT1>
<SECT1 id="build-tree">
<TITLE>Build Tree</TITLE>
<PARA>The <FIRSTTERM>build tree</FIRSTTERM> is the directory
hierarchy in which all <EMPHASIS>generated</EMPHASIS> files
are placed. Generated files consist of the
<FILENAME>makefile</FILENAME>, the compiled object files,
and a dependency file (with a <FILENAME>.d</FILENAME>
extension) for each source file.</PARA>
<SECT2><!--<conditionaltext>-->
<TITLE>Purpose</TITLE>
<PARA>The build tree is where all intermediate object files are
placed. </PARA>
</SECT2>
<SECT2>
<TITLE>How is it modified?</TITLE>
<PARA>Recompiling can modify the object files.</PARA>
</SECT2>
<SECT2>
<TITLE>User applications</TITLE>
<PARA>User application source or binary code should
<EMPHASIS>not</EMPHASIS> go in the build tree. </PARA>
</SECT2>
<SECT2>
<TITLE>Examples of files in this hierarchy</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><FILENAME>ecos-work/language/c/libc/<replaceable>&Version;</replaceable>/src</FILENAME></TERM>
<LISTITEM>
<PARA>The directory in which object files for
the C library are built.</PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECT2>
</SECT1>
<SECT1 id="install-tree">
<TITLE>Install Tree</TITLE>
<PARA>The <FIRSTTERM>install tree</FIRSTTERM> is the location
for all files needed for application development. The
<filename>libtarget.a</filename> library, which contains the
custom-built <productname>eCos</productname> kernel and other components, is placed
in the install tree, along with all packages’ public
header files. If you build the tests, the test executable
programs will also be placed in the install
tree. </PARA>
<PARA>By default, the install tree is created by
<COMMAND>ecosconfig</COMMAND> in a subdirectory of the build
tree called <FILENAME>install</FILENAME>. This can be
modified with the <OPTION>--prefix</OPTION> option (see
<xref linkend="manual-configuration">).
</PARA>
<SECT2><!--<conditionaltext>-->
<TITLE>Purpose</TITLE>
<PARA>The install tree is where the custom-built
<FILENAME>libtarget.a</FILENAME> library, which contains
the <productname>eCos</productname> kernel and other components, is located. The
install tree is also the location for all the header files
that are part of a published interface for their
component. </PARA>
</SECT2>
<SECT2>
<TITLE>How is it modified?</TITLE>
<PARA>Recompiling can replace
<FILENAME>libtarget.a</FILENAME> and the test
executables. </PARA>
</SECT2>
<SECT2>
<TITLE>When is it edited manually?</TITLE>
<PARA>Where a memory layout requires modification without
use of the <productname>eCos</productname> <application>Configuration Tool</application>, the memory layout
files must be edited directly in the install tree. These
files are located at
<FILENAME>install/include/pkgconf/mlt_*.*</FILENAME>.
Note that subsequent modification of the install tree
using the Configuration Tool will result in such manual
edits being lost.</PARA>
</SECT2>
<SECT2>
<TITLE>User applications</TITLE>
<PARA>User application source or binary code should
<EMPHASIS>not</EMPHASIS> go in the install tree. </PARA>
</SECT2>
<SECT2>
<TITLE>Examples of files in this hierarchy</TITLE>
<VARIABLELIST>
<VARLISTENTRY>
<TERM><FILENAME>install/lib/libtarget.a</FILENAME></TERM>
<LISTITEM>
<PARA>The library containing the kernel and other components.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME>install/include/cyg/kernel/kapi.h</FILENAME></TERM>
<LISTITEM>
<PARA>The header file for the kernel C language API.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME>install/include/pkgconf/mlt_arm_pid_ram.ldi</FILENAME></TERM>
<LISTITEM>
<PARA>The linker script fragment describing the memory
layout for linking applications intended for
execution on an ARM PID development board using RAM
startup.</PARA>
</LISTITEM>
</VARLISTENTRY>
<VARLISTENTRY>
<TERM><FILENAME>install/include/stdio.h</FILENAME></TERM>
<LISTITEM>
<PARA>The C library header file for standard I/O. </PARA>
</LISTITEM>
</VARLISTENTRY>
</VARIABLELIST>
</SECT2>
</SECT1>
<SECT1 id="repository-app-build-tree">
<TITLE>Application Build Tree</TITLE>
<PARA>This tree is not part of <productname>eCos</productname> itself: it is the
directory in which <productname>eCos</productname> end users write their own
applications.</PARA>
<PARA>Example applications and their
<FILENAME>Makefile</FILENAME> are located in the component
repository, in the directory
<FILENAME>BASE_DIR</FILENAME><FILENAME>/examples</FILENAME>.
</PARA>
<PARA>There is no imposed format on this directory, but there
are certain compiler and linker flags that must be used to
compile an <productname>eCos</productname> application. The basic set of flags is shown
in the example <FILENAME>Makefile</FILENAME>, and additional
details can be found in <xref linkend="compiler-and-linker-options">. </PARA>
</SECT1>
</CHAPTER>
<CHAPTER id="compiler-and-linker-options">
<TITLE>Compiler and Linker Options</TITLE>
<PARA><productname>eCos</productname> is built using
the GNU C and C++ compilers. <productname>eCos</productname> relies on certain features of these
tools such as constructor priority ordering and selective linking
which are not part of other toolchains.
</PARA>
<PARA>Some <application>GCC</application> options are required for <productname>eCos</productname>,
and others can be useful. This chapter gives a brief description
of the required options as well as some recommended <productname>eCos</productname>-specific options.
All other <application>GCC</application> options (described in the <application>GCC</application> manuals)
are available. </PARA>
<SECT1 id="compiling-c-app">
<TITLE>Compiling a C Application</TITLE>
<PARA>The following command lines demonstrate the
<EMPHASIS>minimum</EMPHASIS> set of options required to
compile and link an <productname>eCos</productname> program written in C. </PARA>
<NOTE>
<PARA>Remember that when this manual shows
<COMMAND><replaceable>TARGET-</replaceable>gcc</COMMAND>
you should use the full name of the cross compiler,
e.g. <COMMAND>i386-elf-gcc</COMMAND>,
<COMMAND>arm-elf-gcc</COMMAND>, or
<COMMAND>sh-elf-gcc</COMMAND>. When compiling for the
synthetic Linux target, use the native
<command>gcc</command> which must have the features
required by <productname>eCos</productname>.</PARA>
</NOTE>
<SCREEN>
$ <replaceable>TARGET-</replaceable>gcc -c -I<EMPHASIS>INSTALL_DIR</EMPHASIS>/include file.c
$ <replaceable>TARGET-</replaceable>gcc -o program file.o -L<EMPHASIS>INSTALL_DIR</EMPHASIS>/lib -Ttarget.ld -nostdlib
</SCREEN>
<NOTE>
<PARA>Certain targets may require extra options, for example
the SPARClite architectures require the option
<OPTION>-mcpu=sparclite</OPTION>. Examine the
<FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/examples/Makefile</FILENAME>
or the “Global compiler flags” option
(CYGBLD_GLOBAL_CFLAGS) in your generated
<productname>eCos</productname> configuration) to see if any extra options are
required, and if so, what they are. </PARA>
<PARA>The following command lines use some other options
which are recommended because they use the
<!-- <index></index> -->selective linking feature:</PARA>
<SCREEN>$ <replaceable>TARGET-</replaceable>gcc -c -I<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/include -I. -ffunction-sections -fdata-sections -g -O2 file.c
$ <replaceable>TARGET-</replaceable>gcc -o program file.o -ffunction-sections -fdata-sections -Wl,--gc-sections -g -O2 \
-L<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/lib -Ttarget.ld -nostdlib
</SCREEN>
</NOTE>
</SECT1>
<SECT1 id="compiling-cpp-app">
<TITLE>Compiling a C++ Application</TITLE>
<PARA>The following command lines demonstrate the
<EMPHASIS>minimum</EMPHASIS> set of options required to
compile and link an <productname>eCos</productname> program written in C++.
</PARA>
<NOTE>
<PARA>Remember that when this manual shows
<COMMAND><replaceable>TARGET-</replaceable>g++</COMMAND>
you should use the full name of the cross compiler,
e.g. <COMMAND>i386-elf-g++</COMMAND>,
<COMMAND>arm-elf-g++</COMMAND>, or
<COMMAND>sh-elf-g++</COMMAND>. When compiling for the
synthetic Linux target, use the native
<command>g++</command> which must have the features
required by <productname>eCos</productname>.</PARA>
</NOTE>
<SCREEN>$ <replaceable>TARGET-</replaceable>g++ -c -I<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/include -fno-rtti -fno-exceptions file.cxx
$ <replaceable>TARGET-</replaceable>g++ -o program file.o -L<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/lib -Ttarget.ld -nostdlib
</SCREEN>
<NOTE>
<PARA>Certain targets may require extra options,
for example the SPARClite architectures require the option
<OPTION>-mcpu=sparclite</OPTION>. Examine the
<FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/packages/targets</FILENAME>
file or <FILENAME><REPLACEABLE>BASE_DIR</REPLACEABLE>/examples/Makefile</FILENAME>
or the “Global compiler flags” option
(CYGBLD_GLOBAL_CFLAGS) in your generated
<productname>eCos</productname> configuration) to see if any extra options are
required, and if so, what they are.</PARA>
<PARA>The following command lines use some other options
which are recommended because they use the
<FIRSTTERM>selective linking</FIRSTTERM> feature:</PARA>
<SCREEN>
$ <replaceable>TARGET-</replaceable>g++ -c -I<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/include -I. -ffunction-sections -fdata-sections -fno-rtti \
-fno-exceptions -finit-priority -g -O2 file.cxx
$ <replaceable>TARGET-</replaceable>g++ -o program file.o -W1,--gc-sections -g -O2 -L<REPLACEABLE>INSTALL_DIR</REPLACEABLE>/lib -Ttarget.ld -nostdlib</SCREEN>
</NOTE>
</SECT1>
</CHAPTER>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -