Skip to content

{C,CXX}FLAGS envs are ignored when {c,cpp}_link_args are specified since Meson 1.8.0 #14640

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

Open
kleisauke opened this issue May 24, 2025 · 0 comments
Milestone

Comments

@kleisauke
Copy link
Contributor

Describe the bug
Similar to #14533, it seems the CFLAGS / CXXFLAGS environment variables are ignored when c_link_args / cpp_link_args are specified via the CLI since Meson 1.8.0. PR #14566 (included in Meson 1.8.1) does not appear to fix this.

To Reproduce

$ export CFLAGS="-fsanitize=address"
$ export CXXFLAGS="$CFLAGS"
$ export LDFLAGS="-I."
$ export CC=clang
$ export CXX=clang++
$ meson init
$ meson setup build -Dc_link_args="$LDFLAGS -Wl,-rpath=\$ORIGIN/lib"
The Meson build system
Version: 1.8.1
Source dir: /home/kleisauke/regression
Build dir: /home/kleisauke/regression/build
Build type: native build
Project name: regression
Project version: 0.1
C compiler for the host machine: clang (clang 20.1.3 "clang version 20.1.3 (Fedora 20.1.3-1.fc42)")
C linker for the host machine: clang ld.bfd 2.44-3
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

regression 0.1

  User defined options
    c_link_args: -I. -Wl,-rpath=$ORIGIN/lib

Found ninja-1.12.1 at /usr/bin/ninja
$ meson compile -vC build
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /home/kleisauke/regression/build -v
ninja: Entering directory `/home/kleisauke/regression/build'
[1/2] clang -Iregression.p -I. -I.. -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -O0 -g -fsanitize=address -MD -MQ regression.p/regression.c.o -MF regression.p/regression.c.o.d -o regression.p/regression.c.o -c ../regression.c
[2/2] clang  -o regression regression.p/regression.c.o -I. -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath=$ORIGIN/lib'
FAILED: regression 
clang  -o regression regression.p/regression.c.o -I. -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath=$ORIGIN/lib'
/usr/bin/ld: /usr/bin/ld: DWARF error: mangled line number section (bad file number)
regression.p/regression.c.o: in function `main':
/home/kleisauke/regression/build/../regression.c:7:(.text+0x36): undefined reference to `__asan_report_load8'
/usr/bin/ld: regression.p/regression.c.o: in function `asan.module_ctor':
regression.c:(.text.asan.module_ctor[asan.module_ctor]+0x5): undefined reference to `__asan_init'
/usr/bin/ld: regression.c:(.text.asan.module_ctor[asan.module_ctor]+0xa): undefined reference to `__asan_version_mismatch_check_v8'
/usr/bin/ld: regression.c:(.text.asan.module_ctor[asan.module_ctor]+0x27): undefined reference to `__asan_register_elf_globals'
/usr/bin/ld: regression.p/regression.c.o: in function `asan.module_dtor':
regression.c:(.text.asan.module_dtor[asan.module_dtor]+0x1d): undefined reference to `__asan_unregister_elf_globals'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Expected behavior

$ meson setup build -Dc_link_args="$LDFLAGS -Wl,-rpath=\$ORIGIN/lib"
The Meson build system
Version: 1.7.2
Source dir: /home/kleisauke/regression
Build dir: /home/kleisauke/regression/build
Build type: native build
Project name: regression
Project version: 0.1
C compiler for the host machine: clang (clang 20.1.3 "clang version 20.1.3 (Fedora 20.1.3-1.fc42)")
C linker for the host machine: clang ld.bfd 2.44-3
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

regression 0.1

  User defined options
    c_link_args: -I. -Wl,-rpath=$ORIGIN/lib

Found ninja-1.12.1 at /usr/bin/ninja
$ meson compile -vC build
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /home/kleisauke/regression/build -v
ninja: Entering directory `/home/kleisauke/regression/build'
[1/2] clang -Iregression.p -I. -I.. -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -O0 -g -fsanitize=address -MD -MQ regression.p/regression.c.o -MF regression.p/regression.c.o.d -o regression.p/regression.c.o -c ../regression.c
[2/2] clang  -o regression regression.p/regression.c.o -I. -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath=$ORIGIN/lib' -fsanitize=address

Additional information
Diff between the successful and failed clang invocation:

@@ -2,5 +2,5 @@ INFO: autodetecting backend as ninja
 INFO: calculating backend command to run: /usr/bin/ninja -C /home/kleisauke/regression/build -v
 ninja: Entering directory `/home/kleisauke/regression/build'
 [1/2] clang -Iregression.p -I. -I.. -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -O0 -g -fsanitize=address -MD -MQ regression.p/regression.c.o -MF regression.p/regression.c.o.d -o regression.p/regression.c.o -c ../regression.c
-[2/2] clang  -o regression regression.p/regression.c.o -I. -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath=$ORIGIN/lib' -fsanitize=address
+[2/2] clang  -o regression regression.p/regression.c.o -I. -Wl,--as-needed -Wl,--no-undefined '-Wl,-rpath=$ORIGIN/lib'
 

(notice the missing -fsanitize=address)

We could workaround this by avoiding cpp_link_args and just use the LDFLAGS environment variable instead, see:
libvips/libvips#4535

System parameters

  • Plain native build
  • Fedora 42
  • Python 3.13.3
  • Meson 1.8.1 (bf17c66)
  • Ninja 1.12.1
kleisauke added a commit to kleisauke/libvips that referenced this issue May 24, 2025
@kleisauke kleisauke changed the title {C,CXX}FLAGS envs are ignored when {c,cpp}_link_args is specified since Meson 1.8.0 {C,CXX}FLAGS envs are ignored when {c,cpp}_link_args are specified since Meson 1.8.0 May 24, 2025
kleisauke added a commit to libvips/libvips that referenced this issue May 24, 2025
@thesamesam thesamesam added this to the 1.8.2 milestone May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants