<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Compiler and Linker Options</TITLE
|
>Compiler and Linker Options</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos User Guide"
|
TITLE="eCos User Guide"
|
HREF="ecos-user-guide.html"><LINK
|
HREF="ecos-user-guide.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="eCos Programming Concepts and Techniques"
|
TITLE="eCos Programming Concepts and Techniques"
|
HREF="ecos-programming-concepts-and-techniques.html"><LINK
|
HREF="ecos-programming-concepts-and-techniques.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="Application Build Tree"
|
TITLE="Application Build Tree"
|
HREF="repository-app-build-tree.html"><LINK
|
HREF="repository-app-build-tree.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Compiling a C++ Application"
|
TITLE="Compiling a C++ Application"
|
HREF="compiling-cpp-app.html"></HEAD
|
HREF="compiling-cpp-app.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos User Guide</TH
|
>eCos User Guide</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="repository-app-build-tree.html"
|
HREF="repository-app-build-tree.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="compiling-cpp-app.html"
|
HREF="compiling-cpp-app.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="CHAPTER"
|
CLASS="CHAPTER"
|
><H1
|
><H1
|
><A
|
><A
|
NAME="COMPILER-AND-LINKER-OPTIONS">Chapter 26. Compiler and Linker Options</H1
|
NAME="COMPILER-AND-LINKER-OPTIONS">Chapter 26. Compiler and Linker Options</H1
|
><DIV
|
><DIV
|
CLASS="TOC"
|
CLASS="TOC"
|
><DL
|
><DL
|
><DT
|
><DT
|
><B
|
><B
|
>Table of Contents</B
|
>Table of Contents</B
|
></DT
|
></DT
|
><DT
|
><DT
|
><A
|
><A
|
HREF="compiler-and-linker-options.html#COMPILING-C-APP"
|
HREF="compiler-and-linker-options.html#COMPILING-C-APP"
|
>Compiling a C Application</A
|
>Compiling a C Application</A
|
></DT
|
></DT
|
><DT
|
><DT
|
><A
|
><A
|
HREF="compiling-cpp-app.html"
|
HREF="compiling-cpp-app.html"
|
>Compiling a C++ Application</A
|
>Compiling a C++ Application</A
|
></DT
|
></DT
|
></DL
|
></DL
|
></DIV
|
></DIV
|
><P
|
><P
|
><SPAN
|
><SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> is built using
|
> is built using
|
the GNU C and C++ compilers. <SPAN
|
the GNU C and C++ compilers. <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> relies on certain features of these
|
> relies on certain features of these
|
tools such as constructor priority ordering and selective linking
|
tools such as constructor priority ordering and selective linking
|
which are not part of other toolchains.
|
which are not part of other toolchains.
|
</P
|
</P
|
><P
|
><P
|
>Some <SPAN
|
>Some <SPAN
|
CLASS="APPLICATION"
|
CLASS="APPLICATION"
|
>GCC</SPAN
|
>GCC</SPAN
|
> options are required for <SPAN
|
> options are required for <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
>,
|
>,
|
and others can be useful. This chapter gives a brief description
|
and others can be useful. This chapter gives a brief description
|
of the required options as well as some recommended <SPAN
|
of the required options as well as some recommended <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
>-specific options.
|
>-specific options.
|
All other <SPAN
|
All other <SPAN
|
CLASS="APPLICATION"
|
CLASS="APPLICATION"
|
>GCC</SPAN
|
>GCC</SPAN
|
> options (described in the <SPAN
|
> options (described in the <SPAN
|
CLASS="APPLICATION"
|
CLASS="APPLICATION"
|
>GCC</SPAN
|
>GCC</SPAN
|
> manuals)
|
> manuals)
|
are available. </P
|
are available. </P
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="COMPILING-C-APP">Compiling a C Application</H1
|
NAME="COMPILING-C-APP">Compiling a C Application</H1
|
><P
|
><P
|
>The following command lines demonstrate the
|
>The following command lines demonstrate the
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>minimum</I
|
>minimum</I
|
></SPAN
|
></SPAN
|
> set of options required to
|
> set of options required to
|
compile and link an <SPAN
|
compile and link an <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> program written in C. </P
|
> program written in C. </P
|
><DIV
|
><DIV
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><BLOCKQUOTE
|
><BLOCKQUOTE
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><P
|
><P
|
><B
|
><B
|
>Note: </B
|
>Note: </B
|
>Remember that when this manual shows
|
>Remember that when this manual shows
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
><TT
|
><TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc</B
|
>gcc</B
|
>
|
>
|
you should use the full name of the cross compiler,
|
you should use the full name of the cross compiler,
|
e.g. <B
|
e.g. <B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>i386-elf-gcc</B
|
>i386-elf-gcc</B
|
>,
|
>,
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>arm-elf-gcc</B
|
>arm-elf-gcc</B
|
>, or
|
>, or
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>sh-elf-gcc</B
|
>sh-elf-gcc</B
|
>. When compiling for the
|
>. When compiling for the
|
synthetic Linux target, use the native
|
synthetic Linux target, use the native
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>gcc</B
|
>gcc</B
|
> which must have the features
|
> which must have the features
|
required by <SPAN
|
required by <SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
>.</P
|
>.</P
|
></BLOCKQUOTE
|
></BLOCKQUOTE
|
></DIV
|
></DIV
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>$ <TT
|
>$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc -c -I<SPAN
|
>gcc -c -I<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>INSTALL_DIR</I
|
>INSTALL_DIR</I
|
></SPAN
|
></SPAN
|
>/include file.c
|
>/include file.c
|
$ <TT
|
$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc -o program file.o -L<SPAN
|
>gcc -o program file.o -L<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>INSTALL_DIR</I
|
>INSTALL_DIR</I
|
></SPAN
|
></SPAN
|
>/lib -Ttarget.ld -nostdlib</PRE
|
>/lib -Ttarget.ld -nostdlib</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><DIV
|
><DIV
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><BLOCKQUOTE
|
><BLOCKQUOTE
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><P
|
><P
|
><B
|
><B
|
>Note: </B
|
>Note: </B
|
>Certain targets may require extra options, for example
|
>Certain targets may require extra options, for example
|
the SPARClite architectures require the option
|
the SPARClite architectures require the option
|
<TT
|
<TT
|
CLASS="OPTION"
|
CLASS="OPTION"
|
>-mcpu=sparclite</TT
|
>-mcpu=sparclite</TT
|
>. Examine the
|
>. Examine the
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
><TT
|
><TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>BASE_DIR</I
|
>BASE_DIR</I
|
></TT
|
></TT
|
>/examples/Makefile</TT
|
>/examples/Makefile</TT
|
>
|
>
|
or the “Global compiler flags” option
|
or the “Global compiler flags” option
|
(CYGBLD_GLOBAL_CFLAGS) in your generated
|
(CYGBLD_GLOBAL_CFLAGS) in your generated
|
<SPAN
|
<SPAN
|
CLASS="PRODUCTNAME"
|
CLASS="PRODUCTNAME"
|
>eCos</SPAN
|
>eCos</SPAN
|
> configuration) to see if any extra options are
|
> configuration) to see if any extra options are
|
required, and if so, what they are. </P
|
required, and if so, what they are. </P
|
><P
|
><P
|
>The following command lines use some other options
|
>The following command lines use some other options
|
which are recommended because they use the
|
which are recommended because they use the
|
selective linking feature:</P
|
selective linking feature:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>$ <TT
|
>$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc -c -I<TT
|
>gcc -c -I<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>INSTALL_DIR</I
|
>INSTALL_DIR</I
|
></TT
|
></TT
|
>/include -I. -ffunction-sections -fdata-sections -g -O2 file.c
|
>/include -I. -ffunction-sections -fdata-sections -g -O2 file.c
|
$ <TT
|
$ <TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>TARGET-</I
|
>TARGET-</I
|
></TT
|
></TT
|
>gcc -o program file.o -ffunction-sections -fdata-sections -Wl,--gc-sections -g -O2 \
|
>gcc -o program file.o -ffunction-sections -fdata-sections -Wl,--gc-sections -g -O2 \
|
-L<TT
|
-L<TT
|
CLASS="REPLACEABLE"
|
CLASS="REPLACEABLE"
|
><I
|
><I
|
>INSTALL_DIR</I
|
>INSTALL_DIR</I
|
></TT
|
></TT
|
>/lib -Ttarget.ld -nostdlib</PRE
|
>/lib -Ttarget.ld -nostdlib</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></BLOCKQUOTE
|
></BLOCKQUOTE
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="repository-app-build-tree.html"
|
HREF="repository-app-build-tree.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-user-guide.html"
|
HREF="ecos-user-guide.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="compiling-cpp-app.html"
|
HREF="compiling-cpp-app.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Application Build Tree</TD
|
>Application Build Tree</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-programming-concepts-and-techniques.html"
|
HREF="ecos-programming-concepts-and-techniques.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>Compiling a C++ Application</TD
|
>Compiling a C++ Application</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|