mesonbuild/meson

Uniform way to link whole libraries

Offen

#3.046 geöffnet am 12.02.2018

 (11 Kommentare) (3 Reaktionen) (1 zugewiesene Person)Python (1.465 Forks)batch import
compilersdependenciesenhancementhelp wanted

Repository-Metriken

Stars
 (4.978 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 139T 13h) (51 gemergte PRs in 30 T)

Beschreibung

Use case

Let's say you have 3 libraries and executable

  • global register, it defines some storage for plugins that automatically register themselves
  • plugin that registers on initialization, can be via __attribute__((constructor)) or static initialization
  • user of the register, also links with plugin
  • executable that interacts with user but does not know about plugin directly.

There are 3 problems in meson that make it hard to deal with this

  1. It is not possible to specify link_whole as part of declare_dependency() call and make executable link with plugin if it is static library.
  2. It is not possible to use shared library with link_whole. So if you use library() and let user specify default_library option, you can't consistently use result.
  3. Shared libraries are not linked without specifying '-Wl,--no-as-needed'. But this option is not really needed for the whole project, most likely for few plugins only.

Example to demonstrate this behavior.

Proposal

  • Add link_whole to declare_dependency(). Semantics is identical to link_with.
  • Allow use of shared libraries in link_whole and add '-Wl,--no-as-needed' if shared library is used.
  • Or add another option link_always, let it accept both static and shared libraries with behavior described above, and add it to declare_dependency() as well.

Caveat

I did not take any other systems or compilers but Linux/GCC/Clang into consideration. Looking for input.

Contributor Guide