diff --git a/libtcc.c b/libtcc.c index 6f88989..de19a64 100644 --- a/libtcc.c +++ b/libtcc.c @@ -829,13 +829,31 @@ static int tcc_compile(TCCState *s1) LIBTCCAPI int tcc_compile_string(TCCState *s, const char *str) { + int i; int len, ret; len = strlen(str); tcc_open_bf(s, "", len); memcpy(file->buffer, str, len); + + len = s->nb_files; ret = tcc_compile(s); tcc_close(); + + /* habdle #pragma comment(lib,) */ + for(i = len; i < s->nb_files; i++) { + /* int filetype = *(unsigned char *)s->files[i]; */ + const char *filename = s->files[i] + 1; + if (filename[0] == '-' && filename[1] == 'l') { + if (tcc_add_library(s, filename + 2) < 0) { + tcc_warning("cannot find '%s'", filename+2); + ret++; + } + } + tcc_free(s->files[i]); + } + s->nb_files = len; + return ret; } diff --git a/tcc.c b/tcc.c index 748726f..c712144 100644 --- a/tcc.c +++ b/tcc.c @@ -317,7 +317,7 @@ int main(int argc, char **argv) const char *filename = s->files[i] + 1; if (filename[0] == '-' && filename[1] == 'l') { if (tcc_add_library(s, filename + 2) < 0) { - tcc_error_noabort("cannot find '%s'", filename); + tcc_error_noabort("cannot find '%s'", filename+2); ret = 1; } } else { diff --git a/tccpp.c b/tccpp.c index 111ea2b..e3c9910 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1420,7 +1420,34 @@ static void pragma_parse(TCCState *s1) *s1->pack_stack_ptr = val; skip(')'); } + } else if (tok == TOK_comment) { + if (s1->ms_extensions) { + next(); + skip('('); + if (tok == TOK_lib) { + next(); + skip(','); + if (tok != TOK_STR) { + tcc_error("invalid library specification"); + } else { + int len = strlen((char *)tokc.cstr->data); + char *file = tcc_malloc(len + 4); /* filetype, "-l", and \0 at the end */ + file[0] = TCC_FILETYPE_BINARY; + file[1] = '-'; + file[2] = 'l'; + strcpy(&file[3],(char *)tokc.cstr->data); + dynarray_add((void ***)&s1->files, &s1->nb_files, file); + } + next(); + tok = TOK_LINEFEED; + } else { + tcc_warning("unknown #pragma %s", get_tok_str(tok, &tokc)); + } + } else { + tcc_warning("#pragma comment(lib) is ignored"); + } } + } /* is_bof is true if first non space token at beginning of file */ diff --git a/tcctok.h b/tcctok.h index 0303814..5e1cf07 100644 --- a/tcctok.h +++ b/tcctok.h @@ -153,6 +153,8 @@ DEF(TOK_ASM_push, "push") DEF(TOK_ASM_pop, "pop") #endif + DEF(TOK_comment, "comment") + DEF(TOK_lib, "lib") /* builtin functions or variables */ #ifndef TCC_ARM_EABI