Evgenii Astafev
Evgenii Astafev

Reputation: 1

How to 'link-whole' external static library in meson?

I'm using GCC/Ubuntu. I need to link my app against external (pre-installed) static library.

It needs to be wrapped with '-Wl,--whole-archive' ... '-Wl,--no-whole-archive'

My naive approach is:

lib = cc.find_library('lib.a', dirs : '/path/to/lib', required : true, static: true)
lib_dep = declare_dependency(link_whole: lib)

Unfortunately, it produces the error below: ERROR: declare_dependency keyword argument "link_whole" can only be self-built targets, external dependencies (including libraries) must go in "dependencies".

Obviously, if I replace 'link_whole' with 'dependencies', it kind of 'works'. Though, I don't get what I want.

I'm not considering messing up with 'link_args', since meson was found reordering args on its own.

Any help appreciated. Thanks.

Upvotes: 0

Views: 110

Answers (1)

mitch_
mitch_

Reputation: 1436

The main issue you have here is that compiler.find_library returns a dep object, i.e. it is already a dependency. As such, it cannot occur in the link_whole argument for declare_dependency, which accepts only lib values, i.e. static/shared libraries buildable by meson.

Upvotes: 0

Related Questions