mesonbuild / meson

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

Wrong external dependency for static libs #6108

Open arnout opened 5 years ago

arnout commented 5 years ago

When linking an external library A that was built statically and that itself depends on another library B, meson will try to link with the dynamic version of library B while it is supposed to be linked with the static version. This is because meson searches for the .so file explicitly instead of relying on the linker's -l expansion.

This issue was introduced by 05b54b476.

It is not easy to create a simple reproducer, mainly because linking statically is not really well supported in meson. But we trigger the issue in Buildroot: http://autobuild.buildroot.net/results/db1740b4777f436324218c52bc7b08e5c21b667d/build-end.log

It can be reproduced with:

git clone http://git.buildroot.org/buildroot
cd buildroot
git checkout 4b6ccd822d67
curl http://autobuild.buildroot.net/results/db1740b4777f436324218c52bc7b08e5c21b667d/defconfig > .config
make olddefconfig
make iputils

To work around this issue, we patch meson so that the --default-library option propagates to the order in which libraries are searched. It's not clear though if this is the best solution.

aduskett commented 4 years ago

Is there any status on this? Would a patch such as this be accepted? https://gitlab.com/buildroot.org/buildroot/-/blob/master/package/meson/0002-Prefer-ext-static-libs-when-default-library-static.patch

xclaesse commented 4 years ago

Building static libraries, and depending on static libraries are 2 different things. I don't think we should mix that.

It would be nice to write a test case to help understand exactly what's your use-case.

As far as I understand, it's the same case as https://github.com/mesonbuild/meson/pull/6629, isn't it?

aduskett commented 4 years ago

I think it's more along the lines of this: https://github.com/mesonbuild/meson/pull/6697