1 diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
2 index fa4407f913..c1f6d11fde 100644
3 --- a/tools/winegcc/winegcc.c
4 +++ b/tools/winegcc/winegcc.c
5 @@ -964,6 +964,7 @@ static void build(struct options* opts)
7 strarray *lib_dirs, *files;
8 strarray *spec_args, *link_args;
9 + strarray *src_args, *lib_args, *ar_args;
10 char *output_file, *output_path;
11 const char *spec_o_name, *libgcc = NULL;
12 const char *output_name, *spec_file, *lang;
13 @@ -1203,17 +1204,20 @@ static void build(struct options* opts)
15 strarray_add(link_args, spec_o_name);
17 + src_args = strarray_alloc();
18 + lib_args = strarray_alloc();
19 + ar_args = strarray_alloc();
20 for ( j = 0; j < files->size; j++ )
22 const char* name = files->base[j] + 2;
23 switch(files->base[j][1])
26 - strarray_add(link_args, strmake("-l%s", name));
27 + strarray_add(lib_args, strmake("-l%s", name));
31 - strarray_add(link_args, name);
32 + strarray_add(src_args, name);
35 if (is_pe && !opts->lib_suffix && strchr(name, '/'))
36 @@ -1231,17 +1235,20 @@ static void build(struct options* opts)
40 - strarray_add(link_args, strmake("-L%s", lib ));
41 - strarray_add(link_args, strmake("-l%s", p ));
42 + strarray_add(lib_args, strmake("-L%s", lib ));
43 + strarray_add(lib_args, strmake("-l%s", p ));
49 - strarray_add(link_args, name);
50 + strarray_add(ar_args, name);
54 + strarray_addall(link_args, src_args);
55 + strarray_addall(link_args, ar_args);
56 + strarray_addall(link_args, lib_args);
58 if (!opts->nostdlib && !is_pe)