Lets say I have library X , and library Y (both are not mine)
and in my executable , I want to add some linker args only for X.
I did a workaround by modifying build.ninja file.
is there a proper way to do so.
I don't understand what you're doing. Can you share an example snippet of your meson.build ?
cmplr = meson.get_compiler('cpp')
library_X = cmplr.find_library('X')
library_Y = cmplr.find_library('Y')
executable('my_project',
sources : ['main.cpp'],
dependencies : [library_X, library_Y],
link_args : ['-Wl,--allow-multiple-definition', '-Wl,--whole-archive'])
I want my build.ninja to be like this
LINK_ARGS = -Wl,--no-undefined -Wl,--as-needed -Wl,-O1 -Wl,--start-group -llibrary_X -Wl,--allow-multiple-definition -Wl,--whole-archive -llibrary_Y ....
instead of
LINK_ARGS = -Wl,--no-undefined -Wl,--as-needed -Wl,-O1 -Wl,--start-group -Wl,--allow-multiple-definition -Wl,--whole-archive -llibrary_X -llibrary_Y ....
How do you get library_Y? You should pass it to link_whole: library_Y instead I guess.
I have updated the comment above.
I have tried linke_whole it tells me that <ExternalLibrary X: True> is not a static library.
although I'm sure it's static
You want library_Y to be static linked with -Wl,--whole-archive and library_X to be dynamic linked, right? Sadly find_library() doesn't have a static : true keyword argument. Don't you have a pkg-config file for that library to get it with dependecy('library_Y', static : true) instead?
Okay I've found a solution .
cmplr = meson.get_compiler('cpp')
library_X = cmplr.find_library('X')
library_Y = cmplr.find_library('Y')
dep_1 = declare_dependency(link_args : ['-Wl,--allow-multiple-definition', '-Wl,--whole-archive'],
dependencies : [library_X])
executable('my_project',
sources : ['main.cpp'],
dependencies : [library_Y, dep_1])
I think that works by chance. It looks like meson just cannot link-whole on external static libraries, only on internal libraries. That would be an interesting feature to add.
Can meson link-whole external static libraries now?
ERROR: <ExternalLibrary edit: True> is not a static library.
Get the same error when I try to add a static external library to be linked whole into my shared libraries.
I think there should have a way to convert external static library into a static_library target in meson..
Do we have any workaround for this now?
okay. here it is a work around for me.
dep = declare_dependency(link_args :
[ '-Wl,--whole-archive'
, get_option('prefix')/'lib/libedit.a'
, '-Wl,--no-whole-archive'
],
dependencies : [libedit_deps]
)
Most helpful comment
I think that works by chance. It looks like meson just cannot link-whole on external static libraries, only on internal libraries. That would be an interesting feature to add.