TCC-DOC(1)
π tcc β Tiny C Compiler π
hiii bestie, welcome to TCC-DOC(1) πΈ the manual for the Tiny C Compiler, rewritten with the love and the chaos it deserves. buckle up, we're going in π¦
β¨ NAME β¨
tcc β Tiny C Compiler. that's it. that's the name. iconic. π
π SYNOPSIS π
usage: tcc [options] [infile1 infile2...] [-run infile args...]
π DESCRIPTION π
okay so here's the tea β β TCC's options are very much like gcc's options. no cap, they're basically cousins. but the main difference (the plot twist, the main character energy) is that TCC can also execute the resulting program directly and hand it runtime arguments. like, compile and run? in one breath? she's doing both, periodt. π
here are some examples so you can feel the logic in your bones:
tcc -run a.cβ compilea.cand execute it directly β¨tcc -run a.c arg1β compilea.cand execute it directly.arg1is given as the first argument to themain()ofa.cπtcc a.c -run b.c arg1β compilea.candb.c, link them together, and execute them.arg1is given as the first argument to themain()of the resulting program π«Άtcc -o myprog a.c b.cβ compilea.candb.c, link them, and generate the executablemyprogπ₯tcc -o myprog a.o b.oβ linka.oandb.otogether and generate the executablemyprogπtcc -c a.cβ compilea.cand generate object filea.oπΈtcc -c asmfile.Sβ preprocess with the C preprocessor and assembleasmfile.Sand generate object fileasmfile.oπ§tcc -c asmfile.sβ assemble (but not preprocess)asmfile.sand generate object fileasmfile.oβ¨tcc -r -o ab.o a.c b.cβ compilea.candb.c, link them together and generate the object fileab.oπ«
π Scripting π
TCC can be invoked from scripts, just like shell scripts. you literally just need to add #!/usr/local/bin/tcc -run at the start of your C source and she's off:
#!/usr/local/bin/tcc -run
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
and YES she can read C source code from standard input when - is used in place of infile. example, because of course:
echo 'main(){puts("hello");}' | tcc -run -
the way that just works?? obsessed. ππ
π OPTIONS π
-cβ Generate an object file. β¨-o outfileβ Put object file, executable, or dll into output file outfile. π¦-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-runoption, separated by spaces:
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
-vβ Display TCC version. π·οΈ-vvβ Show included files. As sole argument, print search dirs.-vvvshows tries too. π-benchβ Display compilation statistics. π
π§ 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). πΈ
-Dsym[=val]β Define preprocessor symbol sym to val. If val is not present, its value is1. Function-like macros can also be defined:-DF(a)=a+1π-Usymβ Undefine preprocessor symbol sym. π-Eβ Preprocess only, to stdout or file (with-o). π
βοΈ Compilation flags βοΈ
Note: each of the following options has a negative form beginning with -fno-.
-funsigned-charβ Let thechartype be unsigned. β¨-fsigned-charβ Let thechartype be signed. π-fno-commonβ Do not generate common symbols for uninitialized data. π«-fleading-underscoreβ Add a leading underscore at the beginning of each C symbol._β¨-fms-extensionsβ Allow a MS C compiler extensions to the language. Currently this assumes a nested named structure declaration without an identifier behaves like an unnamed one. πͺ-fdollars-in-identifiersβ Allow dollar signs in identifiers. π²
β οΈ Warning options β οΈ
-wβ Disable all warnings. (living dangerously, bestie) π
Note: each of the following warning options has a negative form beginning with -Wno-.
-Wimplicit-function-declarationβ Warn about implicit function declaration. π«’-Wunsupportedβ Warn about unsupported GCC features that are ignored by TCC. π§-Wwrite-stringsβ Make string constants be of typeconst char *instead ofchar *. βοΈ-Werrorβ Abort compilation if warnings are issued. π-Wallβ Activate all warnings, except-Werror,-Wunusupportedand-Wwrite-strings. π§±
π Linker options π
-Ldirβ Specify an additional static library path for the-loption. The default library paths are/usr/local/lib,/usr/liband/lib. π-lxxxβ Link your program with dynamic librarylibxxx.soor static librarylibxxx.a. The library is searched in the paths specified by the-Loption andLIBRARY_PATHvariable. π-Bdirβ Set the path where the tcc internal libraries (and include files) can be found (default isPREFIX/lib/tcc). π-sharedβ Generate a shared library instead of an executable. π«Ά-soname nameβ set name for shared library to be used at runtime. π·οΈ-staticβ Generate a statically linked executable (default is a shared linked executable). πΏ-rdynamicβ Export global symbols to the dynamic linker. It is useful when a library opened withdlopen()needs to access executable symbols. π-rβ Generate an object file combining all input files. π§©-Wl,-rpath=pathβ Put custom search path for dynamic libraries into executable. π£οΈ-Wl,--enable-new-dtagsβ When putting a custom search path for dynamic libraries into the executable, create the new ELF dynamic tagDT_RUNPATHinstead of the old legacyDT_RPATH. β¨-Wl,--oformat=fmtβ Use fmt as output format. The supported output formats are:elf32-i386β ELF output format (default) πbinaryβ Binary image (only for executable output) π§±coffβ COFF output format (only for executable output for TMS320C67xx target) β
-Wl,--export-all-symbols-Wl,--export-dynamic
Export global symbols to the dynamic linker. It is useful when a library opened with dlopen() needs to access executable symbols. π
-Wl,-subsystem=console/gui/wince/...β Set type for PE (Windows) executables. πͺ-Wl,-[Ttext=# | section-alignment=# | file-alignment=# | image-base=# | stack=#]β Modify executable layout. π-Wl,-Bsymbolicβ SetDT_SYMBOLICtag. π·οΈ-Wl,-(no-)whole-archiveβ Turn on/off linking of all objects in archives. ποΈ
π 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 pointerinstead of the laconicSegmentation fault. πβ¨-bβ Generate additional support code to check memory allocations and array/pointer bounds.-gis implied. Note that the generated code is slower and bigger in this case. The bound checking code is not included in shared libraries. The main executable should always be compiled with the-b.
There are five environment variables that can be used:
TCC_BOUNDS_WARN_POINTER_ADDβ Print warning when pointer add creates an illegal pointer. β οΈTCC_BOUNDS_PRINT_CALLSβ Print bound checking calls. Can be used for debugging. πTCC_BOUNDS_PRINT_HEAPβ Print heap objects that are not freed at exit of program. ποΈTCC_BOUNDS_PRINT_STATISTICβ Print statistic information at exit of program. πTCC_BOUNDS_NEVER_FATALβ Try to continue in case of a bound checking error. π«Ά
Note: -b is only available on i386 (linux and windows), x86_64 (linux and windows), arm, arm64 and riscv64 for the moment.
-bt[N]β Display N callers in stack traces. This is useful with-gor-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. π£
π§ Misc options π§
-MDβ Generate makefile fragment with dependencies. π-MF depfileβ Use depfile as output for-MD. ποΈ-print-search-dirsβ Print the configured installation directory and a list of library and include directories tcc will search. πΊοΈ-dumpversionβ Print version. π·οΈ
π― Target specific options π―
-mms-bitfieldsβ Use an algorithm for bitfield alignment consistent with MSVC. Default is gcc's algorithm. πͺ-mfloat-abi(ARM only) β Select the float ABI. Possible values:softfpandhard. π-mno-sseβ Do not use sse registers on x86_64. π«-m32, -m64β Pass command line to the i386/x86_64 cross compiler. π
Note: GCC options-Ox,-fxand-mxare ignored. π»
π ENVIRONMENT π
Environment variables that affect how tcc operates. (yes bestie, she reads the room) π
CPATHC_INCLUDE_PATH
A colon-separated list of directories searched for include files, directories given with -I are searched first. πΈ
LIBRARY_PATHβ A colon-separated list of directories searched for libraries for the-loption, directories given with-Lare searched first. π
π SEE ALSO π
cpp(1), gcc(1) β the extended family, we love them π«Ά
π AUTHOR π
Fabrice Bellard β the icon, the legend, the moment π
and that's the whole page bestie!! this was TCC-DOC(1) from the Tiny C Compiler, version 0.9.27, dated 2020-08-14 β go forth and compile, slay, and run directly β¨π
π¦π
π¦ where this page comes from
- debian bookworm: tcc 0.9.27+git20200814.62c30a4a-1 Β· LGPL-2.1-or-later
- ubuntu jammy: tcc 0.9.27+git20200814.62c30a4a-1 Β· LGPL-2.1-or-later
- ubuntu noble: tcc 0.9.27+git20200814.62c30a4a-1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms