From d165e87340c3e802f2d0c6354934c5529386fa84 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 18 Apr 2009 13:17:27 +0200 Subject: libtcc: new api tcc_set_lib_path --- libtcc_test.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libtcc_test.c') 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 #include +#include #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) -- cgit v1.3.1