-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
both_libraries()
does not deal with dependencies correctly
#5452
Comments
That sounds like a bug... But it's weird because we do have unit test for that I think. Ideally you should try to extend this test case to demonstrate the bug: |
Here is a minimal test case demonstrating the issue:
The behaviour I expect is either the static version of first library being linked into the executable, or none at all (depending on what the intended behaviour is, which I'm not clear on). What actually happens is that Meson puts the shared version of first lib into the executable link. EDIT: further simplified |
I think this is because you define |
The original report states that there is a bug using The minimal reproducer just links to both_libraries() and it is expected that meson prefers the shared library when given a choice. So, it is not a minimal reproducer at all. Can someone demonstrate that there is in fact a bug here, and how to trigger it? |
I thought it is clear from the text that the behavior I expect is not what actually happens. If the "both"-ness does not transitively apply to link arguments, then the static part of |
That's a very common misunderstanding of default_library and both_libraries. They control only whether you build a static and/or shared library, but does not control that library dependencies. What I could suggest adding in the Meson API is |
both_libraries() has a great deal of utility. It can be used for installing both static and shared versions of a library to the system installation path. As you indicated in your original report, the expectation if you want to incorporate the static version would be to do: both_libs1 = both_libraries('mylib', 'libfile.c')
static_libs1 = both_libs1.get_static_lib()
both_libs2 = both_libraries('mylib2', 'libfile.c', link_with : static_libs1) However, in your followup reply, you did not use the |
I don't actually understand what this means, can you elaborate? |
To clarify, the issue here is what is supposed to happen when you link |
This would conversely result in the shared version of |
I agree that this greatly limits the usefulness of |
To me it feels like a bug, since it contradicts my intuition (and if it's a "very common misunderstanding", not just mine). |
Adding |
Wouldn't that just push the issue one level up? From a brief look at the documentation, |
Indeed, it would have to work transitively. So:
|
Ah, okay -- thanks for elaborating. So you want both_libraries('lib2', ...) to detect that it is being linked to both_libraries('lib1', ...), and then specialize the dependency to link the static version of lib2 in a different manner from how it links the shared version. Unfortunately, this is not currently how that is expected or designed to work. Perhaps it could be made to be. Here is some more food for thought: curl_dep = dependency('libcurl')
lib1 = both_libraries('lib1', 'lib1.c', dependencies: curl_dep)
executable('exe1', 'exe1.c', link_with: lib1.get_static_lib()) Should the executable "know" that it is linking with the static fork of lib1, and follow that to statically link with libcurl? In general, both_libraries is intended as it was originally implemented, to be sugar for defining a static_library() and a shared_library() with the exact same arguments, hence why they both use the same .get_*_lib() attribute of their dependency. This is a bit problematic in additional ways beyond your ticket -- it's also currently impossible to build a |
Good question. That would depend on whether the object returned by
However, the more I'm thinking about the original issue, the more it seems to me that my project was just slightly pathological in requiring some executables to be fully statically linked, while building others as dynamically linked, both in the same Meson script. |
For something a bit more manual, you can offload at least part of the duplication of values by using one of the following currently existing options: making a dict of kwargs to pass to a library invocation, and then passing the dict as static_library('foo', kwargs: foo_args_dict)
shared_library('foo', kwargs: foo_args_dict) Or use foreach libtype: ['static_library', 'shared_library']
lib1 = build_target(libtype, ....)
lib2 = build_target(libtype, ...., link_with: lib1)
endforeach Both options are a bit more noisy than having |
I think #12632 should address this issue. |
Or dependencies don't deal with
both_libraries()
correctly. Depends on the viewpoint.I'm trying to convert a complicated cross-compiling project into Meson.
We have a bunch of libraries and a bunch of executables. The libraries have dependencies on other libraries. Some executables need to be build statically, so link a static version of libraries that also need to be available as shared for other executables.
The libraries are all represented with
declare_dependency()
objects for convenience.Since
declare_dependency()
does not handle the "bothness" of a library, I tried creating separate shared and static dependencies fromboth_libraries()
.However, when trying to use
both_libraries().get_static_lib()
in a dependency object, it causes shared libraries to be added to the linker command line of the target executable, resulting in failed build. If separateshared_library()
andstatic_library()
are used instead ofboth_libraries()
, everything works as expected.EDIT: Removed last sentence. Using same name for shared and static library actually works, I just made a mistake and effectively tried using
static_library()
alongsideboth_libraries()
.The text was updated successfully, but these errors were encountered: