Problem
Some libraries are not found when compiler.find_library("lib") is used unless linker is changed. A clear example is gsl library (another one is deal_II). When you set linker to CXXFLAGS='-fuse-ld=gold' or CXX=clang++ CXXFLAGS='-fuse-ld=lld', meson finds these libraries without problem.
Configuration example
project('test', 'cpp',
default_options : ['cpp_std=c++14',
'buildtype=release',])
cpp = meson.get_compiler('cpp')
libraries = ['gmp', 'mpfr', 'gsl', 'gslcblas', 'tbb']
foreach lib : libraries
system_lib = cpp.find_library(lib)
endforeach
All libraries are found using this configuration example except 'gsl'. This library is found when linker is changed to ld.gold or ld.lld with clang++.
Meson version
This bug is present in version 0.47.0 and above. I've done a git bisect and the commit that apparently introduced this bug is: af546b52ca0281a595f4395425905c68ff0d21c2
Some relevant log:
Using cached compile:
Cached command line: c++ /tmp/tmpbprgu_zr/testfile.cpp -pipe -D_FILE_OFFSET_BITS=64 -o /tmp/tmpbprgu_zr/output.exe -O0 -fpermissive -Wl,--whole-archive -Wl,--start-group /usr/lib64/libgsl.so -Wl,--end-group -Wl,--no-whole-archive
Code:
int main(int argc, char **argv) { return 0; }
Cached compiler stdout:
Cached compiler stderr:
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ztrsv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_scasum'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_izamax'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dnrm2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zdotc_sub'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cgemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cher2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cdotu_sub'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ddot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zdscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zsyr2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_chemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zgemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ccopy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_isamax'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cswap'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cgeru'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zher'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_daxpy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ctrsv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cdotc_sub'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zgemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_csyrk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ctrmm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sdsdot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_csscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dger'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ctrsm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsyrk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_icamax'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsyr'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsyr2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dtrmv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dasum'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsymv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_strsm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_srot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssyr'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_srotmg'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_scnrm2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_snrm2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zgeru'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zhemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dcopy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsyr2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_drotmg'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ztrmm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dtrmm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_srotm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_chemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dznrm2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_drotm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsymm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_strsv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sdot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssyr2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_idamax'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dtrsm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zhemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zsyrk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dzasum'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_csyr2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zgerc'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sgemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zher2k'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssyr2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zswap'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dgemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sgemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_csymm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_strmm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zsymm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_srotg'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_drotg'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zcopy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dswap'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cher'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ztrmv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zherk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_scopy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_caxpy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zscal'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cgerc'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssymm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ztrsm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cherk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssyrk'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sger'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_strmv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_saxpy'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dgemv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_drot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dsdot'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cgemm'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zdotu_sub'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sswap'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_cher2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_ssymv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_dtrsv'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zher2'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_sasum'
/usr/bin/ld: /usr/lib64/libgsl.so: undefined reference to `cblas_zaxpy'
collect2: error: ld returned 1 exit status
IMO this is bug in libgsl and not in meson.
but even with tat, meson should still find a library.
IMO this is bug in libgsl and not in meson.
I had problems with gsl before, so it is probably a bug in that library. Nevertheless, this library was found before Meson version 0.47.0. Also, Meson finds the library when you change the default linker.
This is a known bug, will be fixed in the stable release.
Duplicate of https://github.com/mesonbuild/meson/issues/3881