Skip to content

No deduplication of some linker flags via static_library dependencies #15503

@jrosdahl

Description

@jrosdahl

Describe the bug

When a static library has dependencies that add linker flags, those flags (at least in some situations) are not deduplicated. For instance, it happens with static_library(..., dependencies: dependency('openmp') or static_library(..., dependencies: meson.get_compiler('c').find_library('z')).

This of course works correctly, but when you see the command line it looks like something has gone awry , especially in a more complex scenario than the example below (we have around 100 -fopenmp arguments in our build at the moment).

To Reproduce

$ touch empty.c
$ cat meson.build
project('example', 'c')

lib1 = static_library('lib1', 'example.c', dependencies: dependency('openmp'))
lib2 = static_library('lib2', 'example.c', dependencies: dependency('openmp'))
shared_library('example', 'example.c', link_with: [lib1, lib2])
$ meson setup build
[...]
$ grep 'LINK_ARGS.*openmp'  build/build.ninja
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,-soname,libexample.so -Wl,--start-group liblib1.a liblib2.a -Wl,--end-group -fopenmp -fopenmp

Note the duplicate -fopenmp arguments.

Expected behavior

-fopenmp arguments are deduplicated.

system parameters

  • Rocky Linux 9.7
  • Python 3.9.25
  • Meson 1.10.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions