> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/TinyCC/tinycc/llms.txt
> Use this file to discover all available pages before exploring further.

# Command reference

> Complete reference for all TCC commands and subcommands

## Synopsis

```bash theme={null}
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 and link

Compile C source files and generate an executable:

```bash theme={null}
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:

```bash theme={null}
tcc -c a.c
```

This compiles `a.c` and generates the object file `a.o`.

**C source**

```bash theme={null}
tcc -c source.c
# Generates: source.o
```

**Assembly with preprocessing**

```bash theme={null}
tcc -c asmfile.S
# Preprocess with C preprocessor and assemble
# Generates: asmfile.o
```

**Assembly without preprocessing**

```bash theme={null}
tcc -c asmfile.s
# Assemble only (no preprocessing)
# Generates: asmfile.o
```

### Link object files

Link object files together to create an executable:

```bash theme={null}
tcc -o myprog a.o b.o
```

### Generate relocatable object file

**-r** `flag`

Generate a relocatable object file by combining all input files.

```bash theme={null}
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:

```bash theme={null}
tcc -run a.c
```

### With arguments

Pass arguments to the compiled program:

```bash theme={null}
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:

```bash theme={null}
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:

```bash theme={null}
tcc "-run -L/usr/X11R6/lib -lX11" ex4.c
```

> [!NOTE]
>
> 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:

```bash theme={null}
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:

```bash theme={null}
tcc -E source.c
```

Save preprocessed output to a file:

```bash theme={null}
tcc -E source.c -o source.i
```

### Preprocessing options

**Standard preprocessing**

```bash theme={null}
tcc -E source.c
# Output includes #line directives
```

**No line directives**

```bash theme={null}
tcc -E -P source.c
# Do not output #line directives
```

**Alternative line directives**

```bash theme={null}
tcc -E -P1 source.c
# Output alternative #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).

```bash theme={null}
# Show all macros with preprocessed code
tcc -E -dD source.c

# Show only macro definitions
tcc -E -dM source.c
```

> [!TIP]
>
> 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:

```bash theme={null}
tcc -shared -o libmylib.so mylib.c
```

**-soname** `string`

Set the name for the shared library to be used at runtime.

```bash theme={null}
tcc -shared -soname libmylib.so.1 -o libmylib.so.1.0 mylib.c
```

## Archive tool

TCC includes an integrated archiver for creating static libraries:

```bash theme={null}
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

```bash theme={null}
# 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:

```bash theme={null}
tcc -impdef lib.dll [-v] [-o lib.def]
```

Create a `.def` file from a DLL:

```bash theme={null}
tcc -impdef kernel32.dll -o kernel32.def
```

## Information commands

### Version information

**-v, --version** `flag`

Display TCC version information.

```bash theme={null}
tcc -v
```

Output:

```
tcc version 0.9.27 (x86_64 Linux)
```

**-dumpversion** `flag`

Print only the version number.

```bash theme={null}
tcc -dumpversion
```

### Verbose output

**-vv** `flag`

Show included files during compilation. As sole argument, print search directories.

```bash theme={null}
# 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.

```bash theme={null}
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.

```bash theme={null}
tcc -h
```

**-hh** `flag`

Display extended help with all options including warnings, flags, and linker options.

```bash theme={null}
tcc -hh
```

## Input from stdin

TCC can read C source code from standard input:

```bash theme={null}
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.

```bash theme={null}
tcc @compile_options.txt
```

Example `compile_options.txt`:

```
-o
myprog
-g
source1.c
source2.c
```

> [!NOTE]
>
> 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.

```bash theme={null}
tcc -bench -c source.c
```

Output:

```
* compiling time: 0.021s (0.021s / 1 idents)
* code time: 0.012s
* data time: 0.003s
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.