Repository: mesonbuild/meson

Issue:
Regression: Trouble finding libraries with find_library
Hi,
I have (again) some very annoying issue with meson not finding stuff where it should find it…

Example:

```
/opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc testfoo.c -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ -lshaderc_combined
```

The command above works, so clearly meson should find the library `shaderc_combined`.

```
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpugg64u87
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpugg64u87/testfile.c -pipe -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpugg64u87/output.exe -O0 -Wl,--start-group -lshaderc_combined -Wl,--end-group -Wl,--allow-shlib-undefined 

Code:
 int main(int argc, char **argv) { return 0; }
Compiler stdout:
 
Compiler stderr:
 lld: error: unknown argument: --allow-shlib-undefined
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)

Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpbmf555fx
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpbmf555fx/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpbmf555fx/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main(int argc, char **argv) {
            void * something;
        }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpb6bsb1cd
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpb6bsb1cd/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpb6bsb1cd/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) >= 0)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpppk8tms6
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpppk8tms6/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpppk8tms6/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) > 0)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpmkiofx0e
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpmkiofx0e/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpmkiofx0e/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) > 1)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpl9tnzna9
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpl9tnzna9/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpl9tnzna9/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) > 3)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpjxrv4w5p
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpjxrv4w5p/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpjxrv4w5p/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) > 7)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmps4p5z81y
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmps4p5z81y/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmps4p5z81y/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) > 15)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmps4p5z81y/testfile.c:3:35: error: 'a' declared as an array with a negative size
        int main() { static int a[1-2*!(sizeof(void *) > 15)]; a[0]=0; return 0; }
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp2dpc5z6l
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp2dpc5z6l/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp2dpc5z6l/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) <= 11)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpsnwu2_h6
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpsnwu2_h6/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpsnwu2_h6/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) <= 9)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpkvgsga80
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpkvgsga80/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmpkvgsga80/output.obj -O0 

Code:
 #include <stdio.h>
        
        int main() { static int a[1-2*!(sizeof(void *) <= 8)]; a[0]=0; return 0; }
Compiler stdout:
 
Compiler stderr:
 
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp3vrkk6ha
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp3vrkk6ha/testfile.c -pipe -c -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp3vrkk6ha/output.obj -O0 --print-search-dirs 

Code:
 
Compiler stdout:
 programs: =/opt/llvm-mingw/bin
libraries: =/opt/llvm-mingw/lib/clang/8.0.0::/opt/llvm-mingw/x86_64-w64-mingw32/lib:/opt/llvm-mingw/lib:/opt/llvm-mingw/x86_64-w64-mingw32/sys-root/mingw/lib

Compiler stderr:
 
Library shaderc_combined found: NO
```

It is a regression introduced between **0.47.1** and **0.47.2**, 9364ff0dce99e52c40f1698341111b81a415551b is the first bad commit.

Log with the previous commit (81b12a6a):

```
Running compile:
Working directory:  /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp71ge82b1
Command line:  /opt/llvm-mingw/bin/x86_64-w64-mingw32-gcc -L/Users/epirat/Projects/VideoLAN/VLC/contrib/x86_64-w64-mingw32/lib/ /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp71ge82b1/testfile.c -pipe -o /var/folders/rw/l97gj1cd6vd_wrf_zjcbycjc0000gn/T/tmp71ge82b1/output.exe -O0 -Wl,--start-group -lshaderc_combined -Wl,--end-group 

Code:
 int main(int argc, char **argv) { return 0; }
Compiler stdout:
 
Compiler stderr:
 
Library shaderc_combined found: YES
```


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -164,6 +164,9 @@ def get_allow_undefined_link_args(self):
             if self.compiler_type.is_osx_compiler:
                 # Apple ld
                 return ['-Wl,-undefined,dynamic_lookup']
+            elif self.compiler_type.is_windows_compiler:
+                # For PE/COFF this is impossible
+                return []
             else:
                 # GNU ld and LLVM lld
                 return ['-Wl,--allow-shlib-undefined']


Test patch: