-
-
Save energygreek/26393a80f3c54227c57fc33454649b28 to your computer and use it in GitHub Desktop.
LibTCC demo - usage example for live c code compilation & execution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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