You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building a shared library which uses external static library (say libA here) internally, I don't want to expose the libA's symbol from my shared library.
One way to achieve this is to set gnu_symbol_visibility: 'inlineshidden' on libA.
But there is also a way to do this without modifying libA: -Wl,--exclude-libs,libA.a in addition to -lA (on Linux) and -Wl,-hidden-lA instead of -lA (on MacOS). This works no matter what the visibility option of libA is.
Unfortunately, doing this in meson will be something like this and a little complicated:
a_proj =subproject(...)
a_dep = a_proj.get_variable('a_dep')
a_lib = a_proj.get_variable('a_lib')
link_depends = []
ifhost_machine.system() =='linux'
a_hidden_dep =declare_dependency(
dependencies: [a_dep],
link_args: ['-Wl,--exclude-libs,'+ fs.name(a_lib.full_path())],
)
elifhost_machine.system() =='darwin'
link_depends += a_lib
a_hidden_dep =declare_dependency(
dependencies: [a_dep.partial_dependency(compile_args: true, includes: true)],
link_args: [
'-L'+ fs.parent(a_lib.full_path()),
'-Wl,-hidden-l'+ a_lib.name(),
],
)
else# On Windows just linking normally is ok for me.# I don't know about other platform...
a_hidden_dep = a_dep
endif# then link it from my library
my_lib =library(
...,
# on MacOS I need to put a_lib into link_depends to avoid linking with -lA,# and declare_dependency do not have link_dependslink_depends: link_depends,
dependencies: a_hidden_dep,
)
# In reality I want to do this only when my_lib is shared and a_lib is static, and otherwise it should be linked normally.# so there will be more if statements than this.
So I thought it would be useful if meson implemented an argument like link_hidden: a_lib.
The text was updated successfully, but these errors were encountered:
Hmm. Kind of lame that Apple ld64 doesn't support --exclude-libs. :(
Note that you can also achieve a comparable effect using an ld version script, which is likewise linker-dependent but doesn't need hacking around partial dependencies in order to erase -lA from the link command.
When building a shared library which uses external static library (say libA here) internally, I don't want to expose the libA's symbol from my shared library.
One way to achieve this is to set
gnu_symbol_visibility: 'inlineshidden'
on libA.But there is also a way to do this without modifying libA:
-Wl,--exclude-libs,libA.a
in addition to-lA
(on Linux) and-Wl,-hidden-lA
instead of-lA
(on MacOS). This works no matter what the visibility option of libA is.Unfortunately, doing this in meson will be something like this and a little complicated:
So I thought it would be useful if meson implemented an argument like
link_hidden: a_lib
.The text was updated successfully, but these errors were encountered: