From 0a50e6c933cb3d470494c203e90808cef6873b06 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Tue, 4 Jan 2011 11:17:52 +0200 Subject: [PATCH] tcc.c: fix an error when you build an object file with '-pthread' key set The problem was partially fixed by Henry in the following patch: tcc.c: skip -lpthread when -c option specified But that patch had one brawback: it is sensitive to argument order, as decision is taken during commandline parsing: $ tcc -c a.c -o a.o -pthread # 1. works fine tcc: error: file 'a.c' not found $ tcc -pthread -c a.c -o a.o # 2. blows tcc: error: cannot specify libraries with -c This patch fixes case 2. Signed-off-by: Sergei Trofimovich --- tcc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tcc.c b/tcc.c index 3c70f73..e0d6386 100644 --- a/tcc.c +++ b/tcc.c @@ -294,6 +294,9 @@ static int parse_args(TCCState *s, int argc, char **argv) const TCCOption *popt; const char *optarg, *p1, *r1; char *r; + int was_pthread; + + was_pthread = 0; /* is set if commandline contains -pthread key */ optind = 0; while (optind < argc) { @@ -375,11 +378,7 @@ static int parse_args(TCCState *s, int argc, char **argv) nb_libraries++; break; case TCC_OPTION_pthread: - /* fixme: these options could be different on your platform */ - if(output_type != TCC_OUTPUT_OBJ){ - dynarray_add((void ***)&files, &nb_files, "-lpthread"); - nb_libraries++; - } + was_pthread = 1; tcc_define_symbol(s, "_REENTRANT", "1"); break; case TCC_OPTION_bench: @@ -494,6 +493,13 @@ static int parse_args(TCCState *s, int argc, char **argv) } } } + /* fixme: these options could be different on your platform */ + if (was_pthread + && output_type != TCC_OUTPUT_OBJ) + { + dynarray_add((void ***)&files, &nb_files, "-lpthread"); + nb_libraries++; + } return optind + 1; }