TCC文档翻译- 2. Command line invocation
2. Command line invocation
命令行帮助
2.1 Quick start
usage: tcc [options] [infile1 infile2…] [‘-run’ infile args…]
快速开始
用法: tcc [options] [infile1 infile2…] [‘-run’ infile args…]
TCC options are a very much like gcc options. The main difference is that TCC can also execute directly the resulting program and give it runtime arguments.
TCC的选项非常类似GCC的选项。主要不同是TCC能在运行时进行执行并给参数(翻译的应该不准确)
Here are some examples to understand the logic:
有很多例子来说明使用方法:
‘tcc -run a.c’
Compile ‘a.c’ and execute it directly
编译'a.c'并马上执行
‘tcc -run a.c arg1’
Compile a.c and execute it directly. arg1 is given as first argument to the main() of a.c.
编译a.c并执行立刻执行它。arg1作为参数传给a.c的main
‘tcc a.c -run b.c arg1’
Compile ‘a.c’ and ‘b.c’, link them together and execute them. arg1 is given as first argument to the main() of the resulting program.
编译a.c和b.c,链接他们并执行,arg1作为main的第一个参数传递给程序
‘tcc -o myprog a.c b.c’
Compile ‘a.c’ and ‘b.c’, link them and generate the executable ‘myprog’.
编译'a.c'和'b.c',链接他们生成可执行程序'myprog'
‘tcc -o myprog a.o b.o’
link ‘a.o’ and ‘b.o’ together and generate the executable ‘myprog’.
链接'a.o'和'b.o',一起生成可执行'myprog'
‘tcc -c a.c’
Compile ‘a.c’ and generate object file ‘a.o’.
编译'a.c'生成目标文件'a.o'
‘tcc -c asmfile.S’
Preprocess with C preprocess and assemble ‘asmfile.S’ and generate object file ‘asmfile.o’.
将'asmfile.S'送进预处理器中,生成目标文件。
‘tcc -c asmfile.s’
Assemble (but not preprocess) ‘asmfile.s’ and generate object file ‘asmfile.o’.
将'asmfile.S'但不进行预处理,生成目标文件。
‘tcc -r -o ab.o a.c b.c’
Compile ‘a.c’ and ‘b.c’, link them together and generate the object file ‘ab.o’.
编译‘a.c’ 和 ‘b.c',链接他们并生成目标文件'ab.o'
Scripting:
TCC can be invoked from scripts, just as shell scripts. You just need to add #!/usr/local/bin/tcc -run at the start of your C source:
你可以像调用SHELL脚本一样调用TCC,只需要在C文件的前面加上 #!/usr/local/bin/tcc -run
#!/usr/local/bin/tcc -run
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
TCC can read C source code from standard input when ‘-’ is used in place of ‘infile’. Example:
TCC能通过标准输入,读取C源码。当'-'被使用的时候,以内联方式使用
echo 'main(){puts("hello");}' | tcc -run -
--------------------------------------------------------------------------------
[ < ] [ > ] [ << ] [ Up ] [ >> ] [Top] [Contents] [Index] [ ? ]
2.2 Option summary
设置语法
General Options:
通用设置:
‘-v’
Display current TCC version, increase verbosity.
显示当前TCC版本,增量版本
‘-c’
Generate an object file (‘-o’ option must also be given).
生成一个目标文件(-o选项必须也指定)
‘-o outfile’
Put object file, executable, or dll into output file ‘outfile’.
将目标文件,可执行文件或者DLL文件输出为'outfile'
‘-Bdir’
Set the path where the tcc internal libraries can be found (default is ‘PREFIX/lib/tcc’).
设置路径使TCC默认库能找到
‘-bench’
Output compilation statistics.
输出编译统计信息,如:
D:\>tcc test.c -bench
1003 idents, 513 lines, 12888 bytes, 0.001 s, 512999 lines/s, 12.9 MB/s
‘-run source [args...]’
Compile file source and run it with the command line arguments args. In order to be able to give more than one argument to a script, several TCC options can be given after the ‘-run’ option, separated by spaces. Example:
编译源码并通过给出的命令行参数运行它。为了能给出超过一个的参数,需要使用-run来显示指定其,例子:
tcc "-run -L/usr/X11R6/lib -lX11" ex4.c
In a script, it gives the following header:
在一个脚本中,它紧接着头部:
#!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11
#include <stdlib.h>
int main(int argc, char **argv)
{
...
}
Preprocessor options:
预处理选项:
‘-Idir’
Specify an additional include path. Include paths are searched in the order they are specified.
指定一个额外的导入路径。编译器会在制定的导入路径中搜索。
System include paths are always searched after. The default system include paths are: ‘/usr/local/include’, ‘/usr/include’ and ‘PREFIX/lib/tcc/include’. (‘PREFIX’ is usually ‘/usr’ or ‘/usr/local’).
系统导入路径稍后搜索头文件。默认的系统导入路径是:‘/usr/local/include’, ‘/usr/include’ and ‘PREFIX/lib/tcc/include’. (‘PREFIX’ is usually ‘/usr’ or ‘/usr/local’).
‘-Dsym[=val]’
Define preprocessor symbol ‘sym’ to val. If val is not present, its value is ‘1’. Function-like macros can also be defined: ‘-DF(a)=a+1’
定义预处理程序符号'sym' 到一个值.如果这个值不存在,他的值是'1' 函数像宏样能定义:‘-DF(a)=a+1’
‘-Usym’
Undefine preprocessor symbol ‘sym’.
未定义预处理符号'sym'
Compilation flags:
编译标志:
Note: each of the following warning options has a negative form beginning with ‘-fno-’.
摘要:不想显示警告请在编译命令后跟随‘-fno-
‘-funsigned-char’
Let the char type be unsigned.
让char类型是无符号的
‘-fsigned-char’
Let the char type be signed.
让char类型有符号
‘-fno-common’
Do not generate common symbols for uninitialized data.
不为通用符号生成未初始化的数据
‘-fleading-underscore’
Add a leading underscore at the beginning of each C symbol.
增加一个下划线在C开始的符号
Warning options:
警告设置:
‘-w’
Disable all warnings.
关闭所有警告
Note: each of the following warning options has a negative form beginning with ‘-Wno-’.
摘要:如果想拒绝警告,在后面加‘-Wno-
‘-Wimplicit-function-declaration’
Warn about implicit function declaration.
提醒一个隐士函数声明
‘-Wunsupported’
Warn about unsupported GCC features that are ignored by TCC.
警告一个GCC不支持特性但TCC忽略的。
‘-Wwrite-strings’
Make string constants be of type const char * instead of char *.
用const char*代替char *作为字符串。
‘-Werror’
Abort compilation if warnings are issued.
‘-Wall’
Activate all warnings, except ‘-Werror’, ‘-Wunusupported’ and ‘-Wwrite-strings’.
把所有的警告选项全都打开。相当于给出了: ‘-Werror’, ‘-Wunusupported’ and ‘-Wwrite-strings’.
Linker options:
‘-Ldir’
Specify an additional static library path for the ‘-l’ option. The default library paths are ‘/usr/local/lib’, ‘/usr/lib’ and ‘/lib’.
‘-lxxx’
Link your program with dynamic library libxxx.so or static library libxxx.a. The library is searched in the paths specified by the ‘-L’ option.
‘-shared’
Generate a shared library instead of an executable (‘-o’ option must also be given).
生成一个共享库代替一个可执行文件(’-o‘选项必须给出)
‘-static’
Generate a statically linked executable (default is a shared linked executable) (‘-o’ option must also be given).
生成一个静态链接库(默认是共享连接)(‘-o’选项必须给出)
‘-rdynamic’
Export global symbols to the dynamic linker. It is useful when a library opened with dlopen() needs to access executable symbols.
输出全局符号标记到动态连接库。对于使用dlopen()访问一个可执行文件时是有用的。
‘-r’
Generate an object file combining all input files (‘-o’ option must also be given).
生成一个目标文件合并所有输入文件('-o'选项必须给出)
‘-Wl,-Ttext,address’
Set the start of the .text section to address.
设置.text段的地址
‘-Wl,--oformat,fmt’
Use fmt as output format. The supported output formats are:
使用fmt作为输出时格式。支持:
elf32-i386
ELF output format (default)
ELF输出格式
binary
Binary image (only for executable output)
二进制镜像(仅仅针对可执行文件)
coff
COFF output format (only for executable output for TMS320C67xx target)
COFF 输出格式(仅对TMS320C67xx target有效)
Debugger options:
调式选项:
‘-g’
Generate run time debug information so that you get clear run time error messages: test.c:68: in function 'test5()': dereferencing invalid pointer instead of the laconic Segmentation fault.
生成运行时调试信息还有显示运行时错误信息的功能:test.c:68: in function 'test5()': dereferencing invalid pointer instead of the laconic Segmentation fault.
‘-b’
Generate additional support code to check memory allocations and array/pointer bounds. ‘-g’ is implied. Note that the generated code is slower and bigger in this case.
生成检查内存分配和指针标志的额外代码。'-g'包含其。提示:使用这个选项会使代码变大和变慢。
‘-bt N’
Display N callers in stack traces. This is useful with ‘-g’ or ‘-b’.
显示调用者N在栈traces。这是使用-g或者-b(译注:翻译的不准确)
Note: GCC options ‘-Ox’, ‘-fx’ and ‘-mx’ are ignored.
摘要:GCC选项‘-Ox’, ‘-fx’ and ‘-mx’是忽略