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 <st@anti-virus.by>
This commit is contained in:
16
tcc.c
16
tcc.c
@ -294,6 +294,9 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
|||||||
const TCCOption *popt;
|
const TCCOption *popt;
|
||||||
const char *optarg, *p1, *r1;
|
const char *optarg, *p1, *r1;
|
||||||
char *r;
|
char *r;
|
||||||
|
int was_pthread;
|
||||||
|
|
||||||
|
was_pthread = 0; /* is set if commandline contains -pthread key */
|
||||||
|
|
||||||
optind = 0;
|
optind = 0;
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
@ -375,11 +378,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
|||||||
nb_libraries++;
|
nb_libraries++;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_pthread:
|
case TCC_OPTION_pthread:
|
||||||
/* fixme: these options could be different on your platform */
|
was_pthread = 1;
|
||||||
if(output_type != TCC_OUTPUT_OBJ){
|
|
||||||
dynarray_add((void ***)&files, &nb_files, "-lpthread");
|
|
||||||
nb_libraries++;
|
|
||||||
}
|
|
||||||
tcc_define_symbol(s, "_REENTRANT", "1");
|
tcc_define_symbol(s, "_REENTRANT", "1");
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_bench:
|
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;
|
return optind + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user