Skip to content
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

Override_options not replacing cpp_link_args as expected in Meson, causing linker flags to be added instead of replaced #14101

Open
manipuladordedados opened this issue Jan 9, 2025 · 2 comments

Comments

@manipuladordedados
Copy link

Hi,
I’ve encountered an issue when using override_options with cpp_link_args in Meson. It appears that cpp_link_args doesn’t replace existing linker flags, but instead adds them. This is problematic for targets like shared_library().
I attempted to filter out -static using the following approach:

cpp_link_args_without_static = []
foreach e : get_option('cpp_link_args')
    if e not in ['-static']
        cpp_link_args_without_static += e
    endif
endforeach

However, even with override_options to adjust cpp_link_args, Meson still appends rather than removing it, which causes compilation issues.

@dcbaker
Copy link
Member

dcbaker commented Jan 9, 2025

How are you using those flags after the fact? I would expect:

cpp_link_args_without_static = []
foreach e : get_option('cpp_link_args')
    if e not in ['-static']
        cpp_link_args_without_static += e
    endif
endforeach

target = library(
   'foo',
   'foo.cpp',
   cpp_link_args : ['-ffake'],
   override_options : {'cpp_link_args' : cpp_link_args_without_static}  # or the array form
)

What that won't affect is anything that comes from a dependency, from the cpp_link_args keyword argument any add_project_link_args calls, etc.

@manipuladordedados
Copy link
Author

How are you using those flags after the fact?

Sorry for not mentioning when I opened the issue. My bad.

shared_library(
    'emilua-preload-libc',
    preload_libc_src,
    override_options : {
        'cpp_link_args' : cpp_link_args_without_static,
    },
)

The project fails to build this target (other targets which can be built with -static work as usual) because the way meson works:

LDFLAGS='-static' meson setup -Ddefault_both_libraries=static -Ddefault_library=static -Dprefer_static=true -Dwrap_mode=forcefallback -Dauto_features=disabled ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants