TCC-DOC(1)

πŸ“¦
version 0.9.27+git20200814.62c30a4a Β· 3 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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 β€” compile a.c and execute it directly ✨
  • tcc -run a.c arg1 β€” compile a.c and execute it directly. arg1 is given as the first argument to the main() of a.c πŸ’–
  • tcc a.c -run b.c arg1 β€” compile a.c and b.c, link them together, and execute them. arg1 is given as the first argument to the main() of the resulting program 🫢
  • tcc -o myprog a.c b.c β€” compile a.c and b.c, link them, and generate the executable myprog πŸ”₯
  • tcc -o myprog a.o b.o β€” link a.o and b.o together and generate the executable myprog πŸ’œ
  • tcc -c a.c β€” compile a.c and generate object file a.o 🌸
  • tcc -c asmfile.S β€” preprocess with the C preprocessor 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 -r -o ab.o a.c b.c β€” compile a.c and b.c, link them together and generate the object file ab.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 -run option, 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. -vvv shows 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 is 1. 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 the char type be unsigned. ✨
  • -fsigned-char β€” Let the char type 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 type const char * instead of char *. ✍️
  • -Werror β€” Abort compilation if warnings are issued. πŸ’€
  • -Wall β€” Activate all warnings, except -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 and LIBRARY_PATH variable. πŸ”
  • -Bdir β€” Set the path where the tcc internal libraries (and include files) can be found (default is PREFIX/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 with dlopen() 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 tag DT_RUNPATH instead of the old legacy DT_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 β€” Set DT_SYMBOLIC tag. 🏷️
  • -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 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. 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 -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. πŸ“£

🧚 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: softfp and hard. 🌊
  • -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, -fx and -mx are ignored. πŸ‘»

🌍 ENVIRONMENT 🌍

Environment variables that affect how tcc operates. (yes bestie, she reads the room) πŸ’œ

  • CPATH
  • C_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 -l option, directories given with -L are 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