Skip to content

Instantly share code, notes, and snippets.

@energygreek
Forked from llandsmeer/libtccdemo.c
Created December 29, 2025 07:50
Show Gist options
  • Select an option

  • Save energygreek/26393a80f3c54227c57fc33454649b28 to your computer and use it in GitHub Desktop.

Select an option

Save energygreek/26393a80f3c54227c57fc33454649b28 to your computer and use it in GitHub Desktop.
LibTCC demo - usage example for live c code compilation & execution
#include <stdio.h>
#include <stdlib.h>
#include <libtcc.h>
void callme(int x) {
printf("hello, %d\n", x);
}
void error_func(void * user, const char * msg) {
printf("TCC Error: %s\n", msg);
exit(1);
}
int main(int argc, char ** argv) {
int err;
TCCState * s = tcc_new();
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
tcc_compile_string(s, "void callme(int); int main() { callme(42); }");
tcc_set_error_func(s, 0, error_func);
tcc_add_symbol(s, "callme", callme);
tcc_run(s, argc, argv);
tcc_delete(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment