TCC(1) | General Commands Manual | TCC(1) |
tcc
— Tiny C
Compiler
tcc |
[options] [infile1 infile2
...] [-run infile
args ...] |
Tiny C
Compiler is a lightweight and fast C compiler. Unlike other C
compilers, it is meant to be self-relying; you do not need an external
assembler or linker, because tcc
does that for
you.
tcc
can run programs
directly from
memory without generating executable files, almost like scripting
languages!
tcc
runs on Linux, Windows, macOS,
FreeBSD, NetBSD and OpenBSD operating systems. tcc
can compile C code for i386, x86_64, arm, arm64 and riscv64
architectures.
-c
-o
outfile-run
source [args ...]tcc
options
can be given after the -run
option, separated by
spaces:
tcc "-run -L/usr/X11R6/lib
-lX11" ex4.c
#!/usr/local/bin/tcc -run
-L/usr/X11R6/lib -lX11
-v
-vv
-vvv
shows too.-bench
-I
dirSystem 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).
-D
sym[=val]sym
to
val
. If val
is not
present, its value is 1
. Function-like macros can
also be defined: -DF(a)=a+1
-U
symsym
.-E
-o
).Note: each of the following options has a
negative form beginning with -fno-
.
-funsigned-char
-fsigned-char
-fno-common
-fleading-underscore
-fms-extensions
-fdollars-in-identifiers
-w
Note: each of the following warning options has
a negative form beginning with -Wno-
.
-Wimplicit-function-declaration
-Wunsupported
-Wwrite-strings
-Werror
-Wall
-Werror
,
-Wunusupported
and
-Wwrite-strings
.-L
dir-l
option. The default library paths are
/usr/local/lib, /usr/lib
and /lib.-l
name-L
option
and LIBRARY_PATH
variable.-B
dir-soname
name-static
-rdynamic
-r
-Wl
,-rpath=
path-Wl
,--enable-new-dtags
DT_RUNPATH
instead of the old legacy
DT_RPATH
.-Wl
,--oformat=
fmt-Wl
,--export-all-symbols
-Wl
,--export-dynamic
-Wl
,-subsystem=
console/gui/wince/...-Wl
,-T
[text=#
| section-alignment=# |
file-alignment=# | image-base=#
| stack=#]Modify executable layout.
-Wl
,-B
symbolicDT_SYMBOLIC
tag.-Wl
,-
[no-]whole-archive-g
test.c:68: in function 'test5()':
dereferencing invalid pointer
Segmentation fault
.-b
-g
is implied.-bt
[N]-g
or -b
.
With executables, additional support for stack traces is included.
A function int
tcc_backtrace
(const
char *fmt, ...) is provided to trigger a
stack trace with a message on demand.
-MD
-MF
depfile-MD
.-print-search-dirs
tcc
will search.-dumpversion
-mms-bitfields
-mfloat-abi
(ARM only)-mno-sse
-m32
,
-m64
Note: gcc(1) options
-O
x,
-f
x and
-m
x are ignored.
Environment variables that affect how tcc
operates.
CPATH
C_INCLUDE_PATH
-I
are searched first.LIBRARY_PATH
-l
option, directories given with
-L
are searched first.Compile a.c and execute it directly:
tcc -run a.c
Compile a.c and execute it directly.
arg1 is given as first argument to the
main()
of a.c.
tcc -run a.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.
tcc a.c -run b.c arg1
Compile a.c and b.c, link them and generate the executable myprog.
tcc -o myprog a.c b.c
Link a.o and b.o together and generate the executable myprog.
tcc -o myprog a.o b.o
Compile a.c and generate object file a.o.
tcc -c a.c
Preprocess with C preprocess and assemble asmfile.S and generate object file asmfile.o.
tcc -c asmfile.S
Assemble (but not preprocess) asmfile.s and generate object file asmfile.o.
tcc -c asmfile.s
Compile a.c and b.c, link them together and generate the object file ab.o.
tcc -r -o ab.o a.c b.c
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:
#!/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. Use
- in the place of input file names. For example:
echo
'main(){puts("hello");}' | tcc -run -
The tcc
utility exits 0 on success,
and >0 if an error occurs.
Fabrice Bellard
December 25, 2020 | OpenBSD 6.8 |