Skip to main content

Output options

-o outfile
string
Specify the output filename for the object file, executable, or shared library.
# Generate executable
tcc -o myprogram source.c

# Generate object file
tcc -c -o myobject.o source.c

# Generate shared library
tcc -shared -o libmylib.so mylib.c
-c
flag
Compile only - generate an object file without linking.
-run
flag
Compile and run the program immediately with optional arguments.

Preprocessor options

Include paths

-Idir
string
Add a directory to the include file search path. Include paths are searched in the order they are specified. System include paths are always searched after user-specified paths.
tcc -I/usr/local/mylib/include -I./include source.c
Default system include paths:
  • /usr/local/include
  • /usr/include
  • PREFIX/lib/tcc/include (usually /usr/lib/tcc/include)
-isystem dir
string
Add a directory to the system include path. Files from system include paths are treated as system headers.
tcc -isystem /opt/include source.c
-nostdinc
flag
Do not search the default system include paths. Only search include paths explicitly provided with -I.
tcc -nostdinc -I./include source.c

Macro definitions

-Dsym[=val]
string
Define a preprocessor symbol. If val is not provided, the value is 1. Function-like macros can also be defined.
# Define simple macro
tcc -DDEBUG source.c

# Define macro with value
tcc -DVERSION=2 source.c

# Define function-like macro
tcc -D'MAX(a,b)=((a)>(b)?(a):(b))' source.c
-Usym
string
Undefine a preprocessor symbol.
tcc -U__STDC__ source.c

Include files

-include file
string
Include the specified file before processing each input file, as if #include "file" appeared at the beginning.
tcc -include config.h source.c

Preprocessing output

-E
flag
Preprocess only - output preprocessed source to stdout or file (with -o).
-P
flag
With -E: do not output #line directives in preprocessed output.
-P1
flag
With -E: output alternative #line directives.
-dD
flag
With -E: output #define directives along with preprocessed code.
-dM
flag
With -E: output only #define directives, no preprocessed code.
# Standard preprocessing
tcc -E source.c

# Preprocessing without line directives
tcc -E -P source.c -o source.i

# Show all macros
tcc -E -dM - < /dev/null
-Wp,-opt
string
Pass option directly to preprocessor. Equivalent to using -opt directly.

Compilation flags

Most compilation flags support a negative form with the -fno- prefix to disable the feature.

Character type

-funsigned-char
flag
Make the char type unsigned by default.
-fsigned-char
flag
Make the char type signed by default.
tcc -funsigned-char source.c

Symbol behavior

-fno-common
flag
Do not generate common symbols for uninitialized global data. Place uninitialized globals in BSS instead.
-fleading-underscore
flag
Add a leading underscore to the beginning of each C symbol (for compatibility with some platforms).

Language extensions

-fms-extensions
flag
Allow Microsoft C compiler extensions. Currently this enables anonymous struct/union declarations without an identifier to behave like unnamed members.
// Enabled with -fms-extensions
struct {
    int x;
    struct {
        int y;
        int z;
    };  // Anonymous struct - members accessible directly
} data;
// Access: data.y, data.z
-fdollars-in-identifiers
flag
Allow dollar signs ($) in C identifiers.
int my$variable = 42;  // Valid with -fdollars-in-identifiers

Function behavior

-freverse-funcargs
flag
Evaluate function arguments from right to left instead of left to right.
-fgnu89-inline
flag
Make extern inline behave like static inline (GNU89 semantics).

Debug and analysis

-fasynchronous-unwind-tables
flag
Generate exception handling frame section (eh_frame). This is enabled by default.
-ftest-coverage
flag
Generate code coverage instrumentation. After running the program, a .tcov file is created with coverage data.
tcc -ftest-coverage program.c -o program
./program
# Creates: program.tcov

Warning options

-w
flag
Disable all warnings.
tcc -w source.c
Most warning options support a negative form with the -Wno- prefix.
-Wall
flag
Enable commonly useful warnings. Includes:
  • -Wimplicit-function-declaration
  • -Wdiscarded-qualifiers
-Werror
flag
Treat all warnings as errors. Can be given an option to enable a specific warning and treat it as an error.
# Treat all warnings as errors
tcc -Werror source.c

# Treat only unsupported warnings as errors
tcc -Werror=unsupported source.c

Specific warnings

-Wimplicit-function-declaration
flag
Warn when a function is called without a prior declaration or prototype.
-Wdiscarded-qualifiers
flag
Warn when type qualifiers like const are dropped (e.g., assigning const char * to char *).
-Wunsupported
flag
Warn about unsupported GCC features and options that are ignored by TCC.
-Wwrite-strings
flag
Make string literals of type const char * instead of char *.
tcc -Wall -Wwrite-strings source.c

Linker options

Library paths

-Ldir
string
Add a directory to the library search path for the -l option.
tcc -L/usr/local/lib -L./lib source.c
Default library paths:
  • /usr/local/lib
  • /usr/lib
  • /lib

Libraries

-lxxx
string
Link with dynamic library libxxx.so or static library libxxx.a. Libraries are searched in paths specified by -L and the LIBRARY_PATH environment variable.
# Link with math library
tcc source.c -lm

# Link with multiple libraries
tcc source.c -lpthread -lm -lrt
-Bdir
string
Set the path where TCC’s internal libraries and include files are located. Default is PREFIX/lib/tcc.

Library generation

-shared
flag
Generate a shared library instead of an executable.
-soname name
string
Set the shared object name (DT_SONAME) to be used at runtime.
-static
flag
Generate a statically linked executable. Links with static versions of libraries. This is not recommended as it may not work correctly with TCC.
Static linking with -static is not fully supported and may not work correctly. TCC primarily targets dynamic linking.
-rdynamic
flag
Export global symbols to the dynamic linker. Useful when a library opened with dlopen() needs to access symbols from the main executable.
-r
flag
Generate a relocatable object file by combining all input files.

Standard library options

-nostdlib
flag
Do not implicitly link with the C standard library (libc), C runtime startup files, and libtcc1.
-Wl,-nostdlib
flag
Do not search the default library paths. Only search paths specified with -L and the LIBRARY_PATH environment variable.
# Compile without standard library
tcc -nostdlib -o program start.o program.c

Advanced linker options

All options starting with -Wl, are passed to the linker:
-Wl,-rpath=path
string
Set custom search path for dynamic libraries in the executable.
tcc -Wl,-rpath=/opt/lib source.c
-Wl,--dynamic-linker=path
string
Set the ELF interpreter (dynamic linker) path.
-Wl,-Ipath
string
Alternative syntax for setting the dynamic linker path.
-Wl,--enable-new-dtags
flag
Create the new ELF dynamic tag DT_RUNPATH instead of the legacy DT_RPATH when setting custom library search paths.
-Wl,--oformat=fmt
string
Set the output format. Supported formats:
  • elf32-i386 or elf64-x86-64: ELF format (default)
  • binary: Raw binary image (executables only)
  • coff: COFF format (TMS320C67xx target only)
  • pe-i386 or pe-x86-64: PE format (Windows)
# Generate raw binary
tcc -Wl,--oformat=binary bootloader.c -o boot.bin
-Wl,--export-all-symbols
flag
Same as -rdynamic - export all symbols to dynamic linker.
-Wl,--export-dynamic
flag
Same as -rdynamic - export all symbols to dynamic linker.
-Wl,-Bsymbolic
flag
Set the DT_SYMBOLIC ELF tag, which makes symbol resolution within the library prefer local definitions.
-Wl,--whole-archive
flag
Include all object files from subsequent static libraries, not just those needed to resolve undefined symbols.
-Wl,--no-whole-archive
flag
Return to normal behavior - only load objects as needed from static libraries.
tcc -Wl,--whole-archive -lmylib -Wl,--no-whole-archive source.c

Executable layout (Advanced)

-Wl,-Ttext=address
string
Set the base address of the code section.
-Wl,--image-base=address
string
Set the base address of the executable.
-Wl,--section-alignment=size
string
Set section alignment in the executable.
-Wl,--file-alignment=size
string
Set file alignment (PE format only).
-Wl,--stack=size
string
Set stack reserve size (PE format only).

Windows-specific options

-Wl,--subsystem=type
string
Set PE (Windows) executable subsystem type: console, gui, wince, etc.
tcc -Wl,--subsystem=console program.c -o program.exe

Debugger options

-g
flag
Generate runtime debug information in STAB format. Provides clear error messages like test.c:68: in function 'test5()': dereferencing invalid pointer instead of just Segmentation fault.
tcc -g program.c -o program
-gdwarf
flag
Generate runtime debug information in DWARF format instead of STAB.
-gdwarf-x
flag
Generate extended DWARF debug information.
-g.pdb
flag
Create a .pdb debug database file (Windows PE targets only).
-b
flag
Compile with built-in memory and bounds checker. Detects memory allocation errors and array/pointer bounds violations at runtime. Implies -g.
tcc -b program.c -o program
./program
# Runtime bounds checking active
The bounds checker (-b) adds significant runtime overhead. Only use during development and testing.
-bt[N]
flag
Link with backtrace support and display up to N callers in stack traces. Useful with -g or -b. Defines the __TCC_BACKTRACE__ macro.
Provides access to:
int tcc_backtrace(const char *fmt, ...);
Example:
# Show up to 10 callers in stack traces
tcc -bt10 -g program.c -o program

Miscellaneous options

-std=version
string
Define the __STDC_VERSION__ macro. Use c11 or gnu11 for C11 standard (sets to 201112), otherwise sets to 199901 (C99).
tcc -std=c11 source.c
-x type
string
Specify the type of the next input file:
  • c: C source file
  • a: Assembly file
  • b: Binary file
  • n: None (reset to auto-detection)
tcc -xc header.h -xn source.c
-O[n]
flag
Define __OPTIMIZE__ macro for optimization level n. -O0 does not define the macro.
tcc -O2 source.c
TCC does minimal optimization. The -O flag mainly affects preprocessor macros for conditional compilation.
-pthread
flag
Preprocess with -D_REENTRANT and link with -lpthread.
tcc -pthread threaded_program.c

Dependency generation

-M
flag
Output Makefile dependency rules instead of compiling. Includes system headers.
-MM
flag
Like -M but only mention user header files, not system headers.
-MD
flag
Generate Makefile dependency file while also compiling.
-MMD
flag
Like -MD but only mention user header files.
-MF depfile
string
Specify the output filename for dependency information (use with -MD or -MMD).
-MP
flag
Add phony targets for each dependency (prevents make errors if headers are removed).
# Generate dependencies while compiling
tcc -MMD -MF source.d -c source.c

# Generate only dependencies
tcc -MM source.c > source.d
-dt
flag
With -run or -E: automatically define test_... macros for testing purposes.

Target-specific options

-m32
flag
Generate 32-bit code (defer to i386 cross compiler if needed).
-m64
flag
Generate 64-bit code (defer to x86_64 cross compiler if needed).
tcc -m32 source.c -o program32
-mms-bitfields
flag
Use Microsoft Visual C++ algorithm for bitfield layout instead of GCC’s algorithm.
-mfloat-abi
string
Select floating-point ABI on ARM. Values: softfp or hard.
-mno-sse
flag
Do not use SSE registers for floating-point operations on x86_64.

Ignored options

The following GCC options are recognized but ignored for compatibility:
-arch -C --param -pedantic -pipe -s -traditional
Use -Wunsupported to get warnings about ignored GCC features and options.

Build docs developers (and LLMs) love