mesonbuild / mesonbuild/meson

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

Open
#14,101 3 comments 0 reactions 0 assignees View on GitHub
documentation options
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported behavior with a shared_library() target, override_options, and cpp_link_args containing -static. Trace how override_options handles compiler and linker argument arrays, then verify that the unwanted flag is replaced rather than appended and that the reproduction no longer causes compilation issues.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.