aboutsummaryrefslogtreecommitdiff
path: root/libtcc_test.c
diff options
context:
space:
mode:
authorgrischka <grischka>2009-04-18 13:17:27 +0200
committergrischka <grischka>2009-04-18 15:08:03 +0200
commitd165e87340c3e802f2d0c6354934c5529386fa84 (patch)
tree07eb2800638ca4daf1e2053c6f83cc4fd5731d99 /libtcc_test.c
parent73ba078d2f703ab991ddc36b3504d96f35466700 (diff)
downloadtinycc-d165e87340c3e802f2d0c6354934c5529386fa84.tar.gz
tinycc-d165e87340c3e802f2d0c6354934c5529386fa84.tar.bz2
libtcc: new api tcc_set_lib_path
Diffstat (limited to 'libtcc_test.c')
-rw-r--r--libtcc_test.c16
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)