diff options
Diffstat (limited to 'libtcc_test.c')
| -rw-r--r-- | libtcc_test.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libtcc_test.c b/libtcc_test.c index d257a72..a602fb0 100644 --- a/libtcc_test.c +++ b/libtcc_test.c @@ -5,6 +5,7 @@ */ #include <stdlib.h> #include <stdio.h> +#include <string.h> #include "libtcc.h" @@ -14,7 +15,7 @@ int add(int a, int b) return a + b; } -char my_program[] = +char my_program[] = "int fib(int n)\n" "{\n" " if (n <= 2)\n" @@ -37,22 +38,27 @@ int main(int argc, char **argv) int (*func)(int); void *mem; int size; - + s = tcc_new(); if (!s) { fprintf(stderr, "Could not create tcc state\n"); exit(1); } - /* MUST BE CALLED before any compilation or file loading */ + /* if tcclib.h and libtcc1.a are not installed, where can we find them */ + if (argc == 2 && !memcmp(argv[1], "lib_path=",9)) + tcc_set_lib_path(s, argv[1]+9); + + /* MUST BE CALLED before any compilation */ tcc_set_output_type(s, TCC_OUTPUT_MEMORY); - tcc_compile_string(s, my_program); + if (tcc_compile_string(s, my_program) == -1) + return 1; /* as a test, we add a symbol that the compiled program can use. You may also open a dll with tcc_add_dll() and use symbols from that */ tcc_add_symbol(s, "add", add); - + /* get needed size of the code */ size = tcc_relocate(s, NULL); if (size == -1) |
