📄 tcc-doc.html
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on March, 31 2008 by texi2html 1.64 --><!--Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>--><HEAD><TITLE>Tiny C Compiler Reference Documentation: </TITLE><META NAME="description" CONTENT="Tiny C Compiler Reference Documentation: "><META NAME="keywords" CONTENT="Tiny C Compiler Reference Documentation: "><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"></HEAD><BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"><A NAME="SEC1"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC2"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ >> ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC36">Index</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_About"> ? </A>]</TD></TR></TABLE><P><A NAME="Introduction"></A><H1> 1. Introduction </H1><!--docid::SEC1::--><P>TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other Ccompilers, it is meant to be self-relying: you do not need anexternal assembler or linker because TCC does that for you.</P><P>TCC compiles so <EM>fast</EM> that even for big projects <CODE>Makefile</CODE>s maynot be necessary. </P><P>TCC not only supports ANSI C, but also most of the new ISO C99standard and many GNUC extensions including inline assembly.</P><P>TCC can also be used to make <EM>C scripts</EM>, i.e. pieces of C sourcethat you run as a Perl or Python script. Compilation is so fast thatyour script will be as fast as if it was an executable.</P><P>TCC can also automatically generate memory and bound checks(see section <A HREF="tcc-doc.html#SEC21">6. TinyCC Memory and Bound checks</A>) while allowing all C pointers operations. TCC can dothese checks even if non patched libraries are used.</P><P>With <CODE>libtcc</CODE>, you can use TCC as a backend for dynamic codegeneration (see section <A HREF="tcc-doc.html#SEC22">7. The <CODE>libtcc</CODE> library</A>).</P><P>TCC mainly supports the i386 target on Linux and Windows. There are alphaports for the ARM (<CODE>arm-tcc</CODE>) and the TMS320C67xx targets(<CODE>c67-tcc</CODE>). More information about the ARM port is available at<A HREF="http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html">http://lists.gnu.org/archive/html/tinycc-devel/2003-10/msg00044.html</A>.</P><P><A NAME="Invoke"></A><HR SIZE="6"><A NAME="SEC2"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC3"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ >> ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC36">Index</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1> 2. Command line invocation </H1><!--docid::SEC2::--><P>[This manual documents version 0.9.24 of the Tiny C Compiler]</P><P><HR SIZE="6"><A NAME="SEC3"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC2"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC4"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ >> ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC36">Index</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 2.1 Quick start </H2><!--docid::SEC3::--><P><TABLE><tr><td> </td><td class=example><pre>usage: tcc [options] [<VAR>infile1</VAR> <VAR>infile2</VAR><small>...</small>] [<SAMP>`-run'</SAMP> <VAR>infile</VAR> <VAR>args</VAR><small>...</small>]</pre></td></tr></table></P><P>TCC options are a very much like gcc options. The main difference is that TCCcan also execute directly the resulting program and give it runtimearguments.</P><P>Here are some examples to understand the logic:</P><P><DL COMPACT><DT><CODE><SAMP>`tcc -run a.c'</SAMP></CODE><DD>Compile <TT>`a.c'</TT> and execute it directly<P><DT><CODE><SAMP>`tcc -run a.c arg1'</SAMP></CODE><DD>Compile a.c and execute it directly. arg1 is given as first argument tothe <CODE>main()</CODE> of a.c.<P><DT><CODE><SAMP>`tcc a.c -run b.c arg1'</SAMP></CODE><DD>Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them together and execute them. arg1 is givenas first argument to the <CODE>main()</CODE> of the resulting program. <P><DT><CODE><SAMP>`tcc -o myprog a.c b.c'</SAMP></CODE><DD>Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them and generate the executable <TT>`myprog'</TT>.<P><DT><CODE><SAMP>`tcc -o myprog a.o b.o'</SAMP></CODE><DD>link <TT>`a.o'</TT> and <TT>`b.o'</TT> together and generate the executable <TT>`myprog'</TT>.<P><DT><CODE><SAMP>`tcc -c a.c'</SAMP></CODE><DD>Compile <TT>`a.c'</TT> and generate object file <TT>`a.o'</TT>.<P><DT><CODE><SAMP>`tcc -c asmfile.S'</SAMP></CODE><DD>Preprocess with C preprocess and assemble <TT>`asmfile.S'</TT> and generateobject file <TT>`asmfile.o'</TT>.<P><DT><CODE><SAMP>`tcc -c asmfile.s'</SAMP></CODE><DD>Assemble (but not preprocess) <TT>`asmfile.s'</TT> and generate object file<TT>`asmfile.o'</TT>.<P><DT><CODE><SAMP>`tcc -r -o ab.o a.c b.c'</SAMP></CODE><DD>Compile <TT>`a.c'</TT> and <TT>`b.c'</TT>, link them together and generate the object file <TT>`ab.o'</TT>.<P></DL><P>Scripting:</P><P>TCC can be invoked from <EM>scripts</EM>, just as shell scripts. You justneed to add <CODE>#!/usr/local/bin/tcc -run</CODE> at the start of your C source:</P><P><TABLE><tr><td> </td><td class=example><pre>#!/usr/local/bin/tcc -run#include <stdio.h>int main() { printf("Hello World\n"); return 0;}</pre></td></tr></table></P><P>TCC can read C source code from <EM>standard input</EM> when <SAMP>`-'</SAMP> is used in place of <SAMP>`infile'</SAMP>. Example:</P><P><TABLE><tr><td> </td><td class=example><pre>echo 'main(){puts("hello");}' | tcc -run -</pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC4"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC3"> < </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC5"> > </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[ << ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[ >> ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC1">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC36">Index</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="tcc-doc.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 2.2 Option summary </H2><!--docid::SEC4::--><P>General Options:</P><P><DL COMPACT><DT><SAMP>`-v'</SAMP><DD>Display current TCC version, increase verbosity.<P><DT><SAMP>`-c'</SAMP><DD>Generate an object file (<SAMP>`-o'</SAMP> option must also be given).<P><DT><SAMP>`-o outfile'</SAMP><DD>Put object file, executable, or dll into output file <TT>`outfile'</TT>.<P><DT><SAMP>`-Bdir'</SAMP><DD>Set the path where the tcc internal libraries can be found (default is<TT>`PREFIX/lib/tcc'</TT>).<P><DT><SAMP>`-bench'</SAMP><DD>Output compilation statistics.<P><DT><SAMP>`-run source [args...]'</SAMP><DD>Compile file <VAR>source</VAR> and run it with the command line arguments<VAR>args</VAR>. In order to be able to give more than one argument to ascript, several TCC options can be given <EM>after</EM> the<SAMP>`-run'</SAMP> option, separated by spaces. Example:<P><TABLE><tr><td> </td><td class=example><pre>tcc "-run -L/usr/X11R6/lib -lX11" ex4.c</pre></td></tr></table></P><P>In a script, it gives the following header:</P><P><TABLE><tr><td> </td><td class=example><pre>#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11#include <stdlib.h>int main(int argc, char **argv){ ...}</pre></td></tr></table></P><P></DL><P>Preprocessor options:</P><P><DL COMPACT><DT><SAMP>`-Idir'</SAMP><DD>Specify an additional include path. Include paths are searched in theorder they are specified.<P>System include paths are always searched after. The default systeminclude paths are: <TT>`/usr/local/include'</TT>, <TT>`/usr/include'</TT>and <TT>`PREFIX/lib/tcc/include'</TT>. (<TT>`PREFIX'</TT> is usually<TT>`/usr'</TT> or <TT>`/usr/local'</TT>).</P><P><DT><SAMP>`-Dsym[=val]'</SAMP><DD>Define preprocessor symbol <SAMP>`sym'</SAMP> toval. If val is not present, its value is <SAMP>`1'</SAMP>. Function-like macros canalso be defined: <SAMP>`-DF(a)=a+1'</SAMP><P><DT><SAMP>`-Usym'</SAMP><DD>Undefine preprocessor symbol <SAMP>`sym'</SAMP>.</DL><P>Compilation flags:</P><P>Note: each of the following warning options has a negative form beginning with<SAMP>`-fno-'</SAMP>.</P><P><DL COMPACT><DT><SAMP>`-funsigned-char'</SAMP><DD>Let the <CODE>char</CODE> type be unsigned.<P><DT><SAMP>`-fsigned-char'</SAMP><DD>Let the <CODE>char</CODE> type be signed.<P><DT><SAMP>`-fno-common'</SAMP><DD>Do not generate common symbols for uninitialized data.<P><DT><SAMP>`-fleading-underscore'</SAMP><DD>Add a leading underscore at the beginning of each C symbol.<P></DL><P>Warning options:</P><P><DL COMPACT><DT><SAMP>`-w'</SAMP><DD>Disable all warnings.<P></DL><P>Note: each of the following warning options has a negative form beginning with<SAMP>`-Wno-'</SAMP>.</P><P><DL COMPACT><DT><SAMP>`-Wimplicit-function-declaration'</SAMP><DD>Warn about implicit function declaration.<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -