meson: 1.3.0 still having problems to detect the linker on Xcode 15 for GCC

Describe the bug

The meson setup step fails with:

meson.build:16:0: ERROR: Unable to detect linker for compiler `gcc -Wl,--version`

To Reproduce

[binaries]
c = 'gcc'
cpp = 'g++'
# Missing on macOS
# ar = 'gcc-ar'
# ranlib = 'gcc-ranlib'
size = 'size'
objdump = 'objdump'
objcopy = 'objcopy'
strip = 'strip'
  • invoke meson with a line like:
meson setup --backend ninja --buildtype debug -D platform-name=native --native-file xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file platform-native/meson/native.ini build/native-meson-gcc11-debug .

Expected behavior

The meson setup step to pass.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?: native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.): Sonoma 14.1, Xcode 15
  • what Python version are you using e.g. 3.8.0: 3.11.4
  • what meson --version: 1.3.0
  • what ninja --version if it’s a Ninja build

In my run, the console reads:

> meson setup --backend ninja --buildtype debug -D platform-name=native --native-file xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file platform-native/meson/native.ini build/native-meson-gcc11-debug .
The Meson build system
Version: 1.3.0
Source dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests
Build dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc11-debug
Build type: native build
Project name: micro-os-plus-micro-test-plus-tests
Project version: undefined

meson.build:16:0: ERROR: Unable to detect linker for compiler `gcc -Wl,--version`
stdout: 
stderr: gcc: warning: could not understand version 14.00.00
collect2 version 11.3.0
/usr/bin/ld -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch x86_64 -o a.out -lcrt1.o -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc/x86_64-apple-darwin17.7.0/11.3.0 -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc/x86_64-apple-darwin17.7.0/11.3.0/../../.. --version -lemutls_w -lgcc -lSystem
ld: unknown options: --version 
collect2: error: ld returned 1 exit status


A full log can be found at /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc11-debug/meson-logs/meson-log.txt

The mentioned log file is:

Build started at 2023-11-26T12:34:24.147848
Main binary: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/xpacks/.bin/meson
Build Options: -Dplatform-name=native -Dbackend=ninja -Dbuildtype=debug --native-file=xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file=platform-native/meson/native.ini
Python system: Darwin
The Meson build system
Version: 1.3.0
Source dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests
Build dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc11-debug
Build type: native build
Project name: micro-os-plus-micro-test-plus-tests
Project version: undefined
-----------
Detecting compiler via: `gcc --version` -> 0
stdout:
gcc (xPack GCC x86_64) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------
stderr:
gcc: warning: could not understand version 14.00.00
-----------
Running command: gcc -E -dM -
-----
-----------
Detecting linker via: `gcc -Wl,--version` -> 1
stderr:
gcc: warning: could not understand version 14.00.00
collect2 version 11.3.0
/usr/bin/ld -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch x86_64 -o a.out -lcrt1.o -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc/x86_64-apple-darwin17.7.0/11.3.0 -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc -L/Users/ilg/Library/xPacks/@xpack-dev-tools/gcc/11.3.0-1.1/.content/bin/../lib/gcc/x86_64-apple-darwin17.7.0/11.3.0/../../.. --version -lemutls_w -lgcc -lSystem
ld: unknown options: --version
collect2: error: ld returned 1 exit status
-----------

meson.build:16:0: ERROR: Unable to detect linker for compiler `gcc -Wl,--version`
stdout:
stderr: gcc: warning: could not understand version 14.00.00
collect2 version 11.3.0

With GCC 12.3 the log shows a slightly different behaviour, apparently it gets the version from… ar. Is this an expected behaviour?

Build started at 2023-11-26T12:31:57.577159
Main binary: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/xpacks/.bin/meson
Build Options: -Dplatform-name=native -Dbackend=ninja -Dbuildtype=debug --native-file=/Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file=/Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/platform-native/meson/native.ini
Python system: Darwin
The Meson build system
Version: 1.3.0
Source dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests
Build dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc12-debug
Build type: native build
Project name: micro-os-plus-micro-test-plus-tests
Project version: undefined
C compiler for the host machine: gcc (gcc 12.3.0 "gcc (xPack GCC x86_64) 12.3.0")
C linker for the host machine: gcc ld64 1015.7
-----------
Detecting linker via: `gcc-ar --version` -> [Errno 2] No such file or directory: 'gcc-ar'
-----------
Detecting linker via: `ar --version` -> 1
stderr:
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]
-----------
C++ compiler for the host machine: g++ (gcc 12.3.0 "g++ (xPack GCC x86_64) 12.3.0")
C++ linker for the host machine: g++ ld64 1015.7
C compiler for the build machine: gcc (gcc 12.3.0 "gcc (xPack GCC x86_64) 12.3.0")
C linker for the build machine: gcc ld64 1015.7
-----------
Detecting linker via: `gcc-ar --version` -> [Errno 2] No such file or directory: 'gcc-ar'
-----------
Detecting linker via: `ar --version` -> 1
stderr:
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]
-----------
C++ compiler for the build machine: g++ (gcc 12.3.0 "g++ (xPack GCC x86_64) 12.3.0")
C++ linker for the build machine: g++ ld64 1015.7
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
...

The GCC 12.3 toolchain is available from https://github.com/xpack-dev-tools/gcc-xpack/releases/tag/v12.3.0-1.

There is also a GCC 13.2, but the behaviour is the same as with 12.3.

To conclude:

  • meson 1.3.0 fails with GCC 11.3, and I had to disable the tests with GCC 11 in my projects
  • apart from this unusual behaviour shown in the log, meson 1.3.0 seems functional with GCC 12 & 13, but I’m not sure that this is the expected behaviour

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 1
  • Comments: 31 (14 by maintainers)

Commits related to this issue

Most upvoted comments

The logs you posted don’t show the linker detection failing. It shows a test executable failing to link

Negative. It doesn’t get that far, it fails early during the setup:

> meson setup --backend ninja --buildtype debug -D platform-name=native --native-file xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file platforms/native/meson/native.ini build/native-meson-gcc11-debug .
The Meson build system
Version: 1.3.99
Source dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests
Build dir: /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc11-debug
Build type: native build
Project name: micro-os-plus-micro-test-plus-tests
Project version: undefined
C compiler for the host machine: gcc (gcc 11.3.0 "gcc (xPack GCC x86_64) 11.3.0")
C linker for the host machine: gcc ld64 1015.7

meson.build:16:0: ERROR: Executables created by cpp compiler g++ are not runnable.

A full log can be found at /Users/ilg/MyProjects/micro-os-plus.github/xPacks/micro-test-plus-xpack.git/tests/build/native-meson-gcc11-debug/meson-logs/meson-log.txt
error: running 'meson setup --backend ninja --buildtype debug -D platform-name=native --native-file xpacks/@micro-os-plus/build-helper/meson/toolchains/gcc-darwin.ini --native-file platforms/native/meson/native.ini build/native-meson-gcc11-debug .' failed
error: running 'xpm run prepare --config native-meson-gcc11-debug' failed

… is ok to probe the linker version by invoking ar? Why not?

What is the relationship between the ar version and the linker version? And, on macOS, ar also fails to respond to --version, so the whole exercise doesn’t make much sense.

According to the attached logs, even while using your fix, with GCC 11 meson tries all kind of tricks, and eventually fails to detect the linker version and breaks the build.

I have difficulties to see the point of all this complicated logic, considering that the latest Apple linker (Sonoma with the latest CLT) no longer provides a --version option.

As for GCC 12 & 13, they pass the build, but do you think that it is ok to probe the linker version by invoking ar?

https://github.com/mesonbuild/meson/pull/12574 did not fix this issue, why did you close it?

Sure looks like gcc is emitting that, not meson.

It is not the reason meson failed; ignore that warning, and focus on the errors; the attached logs are long enough and there are other messages to worry about, for example the linker not understanding --version.