TCCState).
Creating a compilation context
tcc_new
Creates a new TCC compilation context.TCCState*
Pointer to the newly created compilation context, or
NULL if allocation fails.Destroying a compilation context
tcc_delete
Frees a TCC compilation context and all associated resources.TCCState*
required
The compilation context to free.
Setting output type
tcc_set_output_type
Sets the output type for the compilation. Must be called before any compilation.TCCState*
required
The compilation context.
int
required
The type of output to generate. One of:
TCC_OUTPUT_MEMORY(1) - Run code in memoryTCC_OUTPUT_EXE(2) - Executable fileTCC_OUTPUT_DLL(4) - Dynamic libraryTCC_OUTPUT_OBJ(3) - Object fileTCC_OUTPUT_PREPROCESS(5) - Only preprocess
int
Returns 0 on success, -1 on error.
Configuring paths
tcc_set_lib_path
Sets the path where TCC will look for its internal libraries and include files.TCCState*
required
The compilation context.
const char*
required
Path to the TCC library directory (typically contains
include/ and lib/).tcc_add_include_path
Adds a directory to the include file search path.TCCState*
required
The compilation context.
const char*
required
Path to add to the include search path.
int
Returns 0 on success.
tcc_add_sysinclude_path
Adds a system include path to the default system include paths.TCCState*
required
The compilation context.
const char*
required
System include path to add.
int
Returns 0 on success.
Setting options
tcc_set_options
Sets compiler options as if passed on the command line. Multiple calls are supported.TCCState*
required
The compilation context.
const char*
required
Command-line style options (e.g., “-Wall -O2”).
int
Returns 0 on success, -1 on error.
Error handling
tcc_set_error_func
Sets a custom error and warning callback.TCCState*
required
The compilation context.
void*
User data pointer passed to the error callback (can be
NULL).TCCErrorFunc*
Callback function for errors and warnings. If
NULL, errors are printed to stderr.Preprocessor configuration
tcc_define_symbol
Defines a preprocessor symbol.TCCState*
required
The compilation context.
const char*
required
Symbol name. Can be “sym=val” form, or just “sym”.
const char*
Symbol value. If
NULL and sym doesn’t contain ’=’, defaults to “1”.tcc_undefine_symbol
Undefines a preprocessor symbol.TCCState*
required
The compilation context.
const char*
required
Symbol name to undefine.
Custom memory allocator
tcc_set_realloc
Sets a custom memory allocator for all TCC allocations. This is a global setting.TCCReallocFunc*
Custom realloc-style function. If
NULL, uses the default allocator.
The function should free memory when size is 0.