mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.64k stars 1.64k forks source link

meson seems to append '.lib' to all pkg-config libs on windows #13859

Open MicK7 opened 3 weeks ago

MicK7 commented 3 weeks ago

Describe the bug

When I add hdf5 as a dependency to a C piece of code on windows, ie `

hdf5_dep = dependency('hdf5', language:'c', required: true)

I end up with a link failure of msvc

FAILED: CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd
"link"  /MACHINE:x64 /OUT:CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/meson-generated_CGNS_MAP_EmbeddedCHLone.pyx.c.obj CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/l3.c.obj CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/error.c.obj CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/linksearch.c.obj CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/sha256.c.obj CGNS/MAP/EmbeddedCHLone.cp310-win_amd64.pyd.p/SIDStoPython.c.obj "/release" "/nologo" "/OPT:REF" "/DLL" "/IMPLIB:CGNS\MAP\EmbeddedCHLone.cp310-win_amd64.lib" "C:\ProgramData\mambaforge\Library\lib\hdf5_hl.lib" "C:/ProgramData/mambaforge/Library/lib/hdf5.lib" "/LIBPATH:C:/ProgramData/mambaforge/Library/lib" "shlwapi.lib" "C:/ProgramData/mambaforge/Library/lib/libcurl.lib.lib" "optimized.lib" "C:/ProgramData/mambaforge/Library/lib/libssl.lib.lib" "debug.lib" "C:/ProgramData/mambaforge/Library/lib/libcrypto.lib.lib" "C:/ProgramData/mambaforge/Library/lib/z.lib.lib" "C:/ProgramData/mambaforge/Library/lib/szip.lib.lib" "C:\ProgramData\mambaforge\libs\python310.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"
LINK : fatal error LNK1181: cannot open input file 'C:\ProgramData\mambaforge\Library\lib\libcurl.lib.lib'

The hdf5.pc used by meson was generated by a cmake build and contains:

prefix=C:/ProgramData/mambaforge/Library
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: hdf5
Description: HDF5 (Hierarchical Data Format 5) Software Library
Version: 1.14.3

Cflags: -I${includedir}
Libs: -L${libdir}  -lhdf5
Requires:
Libs.private:  -lshlwapi -lC:/ProgramData/mambaforge/Library/lib/libcurl.lib -loptimized -lC:/ProgramData/mambaforge/Library/lib/libssl.lib -ldebug -loptimized -lC:/ProgramData/mambaforge/Library/lib/libcrypto.lib -ldebug -lC:/ProgramData/mambaforge/Library/lib/z.lib -lC:/ProgramData/mambaforge/Library/lib/szip.lib -lC:/ProgramData/mambaforge/Library/lib/szip.lib
Requires.private:

The Libs.private seems to be a part added to the linking and modified by meson by appending a '.lib'

To Reproduce

Create a simple C program that do nothing but contains

#include "hdf5.h"

int main()
{
int a =1;
a = a+2;
return 0;
}

The meson.build should contains

hdf5_dep = dependency('hdf5', language:'c', required: true)

executable('myapp',
main.c,
dependencies: [hdf5_dep]) 

Expected behavior

Linking to hdf5 on windows should work and meson should not append ".lib" when it is already present at end of file.

system parameters

rgommers commented 3 weeks ago

That hd5.pc file seems to be buggy. Including -ldebug -loptimized is certainly wrong. Then, Libs.private still includes a mix of library names with and without .lib appended, because of -lshlwapi. If after removing -ldebug and -loptimized things don't work, can you try changing -lshlwapi to -lshlwapi.lib?