Skip to main content

Synopsis

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:
This compiles a.c and b.c, links them together, and generates the executable myprog.

Compile only

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

Generate relocatable object file

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

Run command

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:

With arguments

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

Multiple source files

Compile multiple files and execute them:
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:
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:

Preprocessing commands

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

Preprocessing options

Show macro definitions

flag
With -E: output #define directives along with preprocessed code.
flag
With -E: output only #define directives (no preprocessed code).
To see all predefined macros, use: tcc -E -dM - < /dev/null (Linux/macOS) or tcc -E -dM - < nul (Windows)

Shared library commands

flag
Generate a shared library instead of an executable.
Create a shared library:
string
Set the name for the shared library to be used at runtime.

Archive tool

TCC includes an integrated archiver for creating static libraries:

Archive operations

flag
Create the archive.
flag
Replace or add files to the archive.
flag
Create or update the archive symbol index.
flag
List the contents of the archive.
flag
Verbose output.
flag
Extract files from the archive.

Examples

Import library tool (Windows)

On Windows, TCC can create import definition files from DLLs:
Create a .def file from a DLL:

Information commands

Version information

flag
Display TCC version information.
Output:
flag
Print only the version number.

Verbose output

flag
Show included files during compilation. As sole argument, print search directories.
flag
Show included files and all file search attempts.

Search paths

flag
Print the configured installation directory and list of library and include directories that TCC will search.
Output:

Help commands

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

Input from stdin

TCC can read C source code from standard input:
The - character is used in place of the input filename to indicate stdin.

Response files

string
Read command-line arguments from a file. Each line in the file is treated as a separate argument.
Example compile_options.txt:
Response files are useful for very long command lines that might exceed shell limits.

Compilation statistics

flag
Display compilation statistics including time and memory usage.
Output: