mirror of
https://github.com/frida/tinycc
synced 2024-12-24 22:16:49 +03:00
libtcc: new api tcc_set_lib_path
This commit is contained in:
parent
73ba078d2f
commit
d165e87340
2
Makefile
2
Makefile
@ -305,7 +305,7 @@ libtcc_test$(EXESUF): libtcc_test.c libtcc.a
|
||||
$(CC) $(CFLAGS) -o $@ $< libtcc.a $(LIBS)
|
||||
|
||||
libtest: libtcc_test
|
||||
./libtcc_test
|
||||
./libtcc_test lib_path=.
|
||||
|
||||
# targets for development
|
||||
|
||||
|
3
libtcc.h
3
libtcc.h
@ -92,6 +92,9 @@ int tcc_relocate(TCCState *s1, void *ptr);
|
||||
/* return symbol value or NULL if not found */
|
||||
void *tcc_get_symbol(TCCState *s, const char *name);
|
||||
|
||||
/* set CONFIG_TCCDIR at runtime */
|
||||
void tcc_set_lib_path(TCCState *s, const char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -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)
|
||||
|
19
tcc.c
19
tcc.c
@ -1122,7 +1122,7 @@ char *normalize_slashes(char *path)
|
||||
return path;
|
||||
}
|
||||
|
||||
char *w32_tcc_lib_path(void)
|
||||
void tcc_set_lib_path_w32(TCCState *s)
|
||||
{
|
||||
/* on win32, we suppose the lib and includes are at the location
|
||||
of 'tcc.exe' */
|
||||
@ -1134,7 +1134,7 @@ char *w32_tcc_lib_path(void)
|
||||
else if (p > path)
|
||||
p--;
|
||||
*p = 0;
|
||||
return strdup(path);
|
||||
tcc_set_lib_path(s, path);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -10967,6 +10967,12 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
|
||||
flag_name, value);
|
||||
}
|
||||
|
||||
/* set CONFIG_TCCDIR at runtime */
|
||||
void tcc_set_lib_path(TCCState *s, const char *path)
|
||||
{
|
||||
tcc_lib_path = tcc_strdup(path);
|
||||
}
|
||||
|
||||
#if !defined(LIBTCC)
|
||||
|
||||
static int64_t getclock_us(void)
|
||||
@ -11217,7 +11223,7 @@ int parse_args(TCCState *s, int argc, char **argv)
|
||||
break;
|
||||
case TCC_OPTION_B:
|
||||
/* set tcc utilities path (mainly for tcc development) */
|
||||
tcc_lib_path = optarg;
|
||||
tcc_set_lib_path(s, optarg);
|
||||
break;
|
||||
case TCC_OPTION_l:
|
||||
dynarray_add((void ***)&files, &nb_files, r);
|
||||
@ -11350,11 +11356,10 @@ int main(int argc, char **argv)
|
||||
char objfilename[1024];
|
||||
int64_t start_time = 0;
|
||||
|
||||
#ifdef _WIN32
|
||||
tcc_lib_path = w32_tcc_lib_path();
|
||||
#endif
|
||||
|
||||
s = tcc_new();
|
||||
#ifdef _WIN32
|
||||
tcc_set_lib_path_w32(s);
|
||||
#endif
|
||||
output_type = TCC_OUTPUT_EXE;
|
||||
outfile = NULL;
|
||||
multiple_files = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user