Adding libraries
tcc_add_library
Links a library to the compiled code. The library name follows the convention used by the-l linker option.
TCCState*
required
The compilation context.
const char*
required
Library name without the “lib” prefix or file extension.
For special cases, prefix with
: to use an exact filename.int
Returns 0 on success, -1 on error.
- Dynamic libraries (
.so,.dylib, or.dlldepending on platform) - Static libraries (
.a)
tcc_add_library_path
Adds a directory to the library search path (equivalent to-L option).
TCCState*
required
The compilation context.
const char*
required
Directory path to add to the library search path.
int
Returns 0 on success.
Adding symbols
tcc_add_symbol
Adds a symbol (function or variable) to the compiled program, making host application symbols available to compiled code.TCCState*
required
The compilation context.
const char*
required
Symbol name (must match the name used in compiled code).
const void*
required
Pointer to the function or variable.
int
Returns 0 on success, -1 on error.
Output file generation
tcc_output_file
Generates an output file (executable, library, or object). Do not calltcc_relocate() before this.
TCCState*
required
The compilation context.
const char*
required
Path for the output file.
int
Returns 0 on success, -1 on error.
Complete linking example
Platform-specific notes
Windows (PE format)
On Windows, dynamically linked data needs thedllimport attribute:
Library search order
Libraries are searched in this order:- Paths specified with
tcc_add_library_path() - Default system paths (
/usr/local/lib,/usr/lib,/lib) - Paths from
LIBRARY_PATHenvironment variable