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