TheDocumentation 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.
libtcc library enables you to use TCC as a backend for dynamic code generation. It allows you to compile C code at runtime and execute it directly in memory.
Key features
- In-memory compilation: Compile C source code to executable code in memory without generating intermediate files
- Symbol management: Add and retrieve symbols (functions and variables) dynamically
- Fast compilation: Leverage TCC’s extremely fast compilation speed
- Flexible output: Generate executables, shared libraries, object files, or run code directly in memory
- Error handling: Custom error and warning callbacks for integration into your application
Basic workflow
Using libtcc follows a simple pattern:- Initialize: Create a new compilation context with
tcc_new() - Configure: Set output type, include paths, and compiler options
- Compile: Add C source code using
tcc_compile_string()ortcc_add_file() - Link: Add libraries and symbols with
tcc_add_library()andtcc_add_symbol() - Execute: Either run code in memory or output to a file
- Cleanup: Free resources with
tcc_delete()
Quick example
Output types
libtcc supports multiple output types, set viatcc_set_output_type():
TCC_OUTPUT_MEMORY: Compile and run code in memory (default for dynamic generation)TCC_OUTPUT_EXE: Generate an executable fileTCC_OUTPUT_DLL: Generate a dynamic libraryTCC_OUTPUT_OBJ: Generate an object fileTCC_OUTPUT_PREPROCESS: Only preprocess the source code
Thread safety
Custom memory allocation
You can provide a custom memory allocator usingtcc_set_realloc() before creating any TCCState instances. This affects all memory allocation performed by TCC.
Error handling
By default, errors and warnings are printed to stderr. You can set a custom error handler withtcc_set_error_func() to integrate TCC’s diagnostics into your application’s logging or UI.
Next steps
- Initialization - Learn how to create and configure a TCC compilation context
- Compilation - Compile C source code from strings or files
- Linking - Link libraries and manage dependencies
- Execution - Run compiled code or generate output files
- Symbols - Work with symbols and function pointers