Skip to main content

Synopsis

tcc [options] [infile1 infile2...] [-run infile args...]
TCC options are very similar to GCC options. The main difference is that TCC can also execute the resulting program directly and pass it runtime arguments.

Basic compilation commands

Compile C source files and generate an executable:
tcc -o myprog a.c b.c
This compiles a.c and b.c, links them together, and generates the executable myprog.

Compile only

-c
flag
Compile only - generate an object file without linking.
Compile a C source file to an object file:
tcc -c a.c
This compiles a.c and generates the object file a.o.
tcc -c source.c
# Generates: source.o
Link object files together to create an executable:
tcc -o myprog a.o b.o

Generate relocatable object file

-r
flag
Generate a relocatable object file by combining all input files.
tcc -r -o ab.o a.c b.c
This compiles a.c and b.c, links them together, and generates the relocatable object file ab.o.

Run command

-run
flag
Compile source file(s) and run the resulting program immediately with optional command-line arguments.

Basic execution

Compile and execute a C program directly:
tcc -run a.c

With arguments

Pass arguments to the compiled program:
tcc -run a.c arg1 arg2
The arguments arg1 and arg2 are passed to the main() function of a.c.

Multiple source files

Compile multiple files and execute them:
tcc a.c -run b.c arg1
This compiles a.c and b.c, links them together, and executes the resulting program with arg1 as the first argument.

With TCC options

You can pass TCC options after -run by enclosing them in quotes:
tcc "-run -L/usr/X11R6/lib -lX11" ex4.c
When using -run, TCC compiles the code in memory and executes it immediately without creating an executable file on disk.

Custom stdin

Redirect stdin for the running program:
tcc -run -rstdin input.txt program.c

Preprocessing commands

-E
flag
Preprocess only - output the preprocessed source to stdout or file (with -o).
Preprocess a C source file:
tcc -E source.c
Save preprocessed output to a file:
tcc -E source.c -o source.i

Preprocessing options

tcc -E source.c
# Output includes #line directives

Show macro definitions

-dD
flag
With -E: output #define directives along with preprocessed code.
-dM
flag
With -E: output only #define directives (no preprocessed code).
# Show all macros with preprocessed code
tcc -E -dD source.c

# Show only macro definitions
tcc -E -dM source.c
To see all predefined macros, use: tcc -E -dM - < /dev/null (Linux/macOS) or tcc -E -dM - < nul (Windows)

Shared library commands

-shared
flag
Generate a shared library instead of an executable.
Create a shared library:
tcc -shared -o libmylib.so mylib.c
-soname
string
Set the name for the shared library to be used at runtime.
tcc -shared -soname libmylib.so.1 -o libmylib.so.1.0 mylib.c

Archive tool

TCC includes an integrated archiver for creating static libraries:
tcc -ar [crstvx] lib.a [files...]

Archive operations

c
flag
Create the archive.
r
flag
Replace or add files to the archive.
s
flag
Create or update the archive symbol index.
t
flag
List the contents of the archive.
v
flag
Verbose output.
x
flag
Extract files from the archive.

Examples

# Create a static library
tcc -ar cr libmylib.a file1.o file2.o file3.o

# List archive contents
tcc -ar t libmylib.a

# Extract files from archive
tcc -ar x libmylib.a

Import library tool (Windows)

On Windows, TCC can create import definition files from DLLs:
tcc -impdef lib.dll [-v] [-o lib.def]
Create a .def file from a DLL:
tcc -impdef kernel32.dll -o kernel32.def

Information commands

Version information

-v, --version
flag
Display TCC version information.
tcc -v
Output:
tcc version 0.9.27 (x86_64 Linux)
-dumpversion
flag
Print only the version number.
tcc -dumpversion

Verbose output

-vv
flag
Show included files during compilation. As sole argument, print search directories.
# Show included files
tcc -vv -c source.c

# Print search directories
tcc -vv
-vvv
flag
Show included files and all file search attempts.

Search paths

-print-search-dirs
flag
Print the configured installation directory and list of library and include directories that TCC will search.
tcc -print-search-dirs
Output:
install: /usr/local/lib/tcc
include:
  /usr/local/include
  /usr/include
  /usr/local/lib/tcc/include
libraries:
  /usr/local/lib
  /usr/lib
  /lib

Help commands

-h
flag
Display basic help message with common options.
tcc -h
-hh
flag
Display extended help with all options including warnings, flags, and linker options.
tcc -hh

Input from stdin

TCC can read C source code from standard input:
echo 'main(){puts("hello");}' | tcc -run -
The - character is used in place of the input filename to indicate stdin.

Response files

@listfile
string
Read command-line arguments from a file. Each line in the file is treated as a separate argument.
tcc @compile_options.txt
Example compile_options.txt:
-o
myprog
-g
source1.c
source2.c
Response files are useful for very long command lines that might exceed shell limits.

Compilation statistics

-bench
flag
Display compilation statistics including time and memory usage.
tcc -bench -c source.c
Output:
* compiling time: 0.021s (0.021s / 1 idents)
* code time: 0.012s
* data time: 0.003s

Build docs developers (and LLMs) love