meson: "Unable to detect linker for compiler" error in an osx cross-compile environment

Ran into it while trying to build dav1d project for macos/x64, using meson-1.0.2 with python 3.7 on i686-linux. The following copied from meson-log.txt:

-----
Detecting compiler via: /tmp/cc.sh --version
compiler returned <subprocess.Popen object at 0xb70d6e6c>
compiler stdout:
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-apple-darwin9
Thread model: posix

compiler stderr:

Running command: /tmp/cc.sh -E -dM -
-----
Detecting linker via: /tmp/cc.sh -Wl,--version
linker returned <subprocess.Popen object at 0xb68dafec>
linker stdout:

linker stderr:
ld: unknown option: --version
clang: error: linker command failed with exit code 1 (use -v to see invocation)

-----
Detecting Apple linker via: /tmp/cc.sh -Wl,-v
linker stdout:

linker stderr:
241.9
configured to support archs: armv4t armv5 armv6 armv7 armv7f armv7k armv7s armv6m armv7m armv7em armv8 arm64 arm64v8 i386 x86_64 x86_64h
Library search paths:
	/opt/MacOSX10.8.sdk/usr/lib
	/opt/MacOSX10.8.sdk/usr/local/lib
Framework search paths:
	/opt/MacOSX10.8.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


../meson.build:25:0: ERROR: Unable to detect linker for compiler `/tmp/cc.sh -Wl,--version`
stdout: 
stderr: ld: unknown option: --version
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The cross-build file is like this:

[binaries]
c = '/tmp/cc.sh'
cpp = '/tmp/cc.sh'
ld = 'x86_64-apple-darwin9-ld'
ar = 'x86_64-apple-darwin9-ar'
ranlib = 'x86_64-apple-darwin9-ranlib'
strip = 'x86_64-apple-darwin9-strip'

[host_machine]
system = 'darwin'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

The x86_64-apple-darwin9-XXX tools are built from cctools-port project. And, cc.sh is simply a wrapper around clang:

#!/bin/sh

exec clang -target x86_64-apple-darwin9 -arch x86_64 -mlinker-version=341.9 -isysroot /opt/MacOSX10.8.sdk -B /opt/cctools-port/bin -mmacosx-version-min=10.6 "$@"

Is there a way around this?

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

I just updated my system to macOS 14.1 with the latest CLT/Xcode 15 and meson (1.0.2) can no longer be used with it.

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

The linker is:

ilg@wksi ~ % /usr/bin/ld -v       
@(#)PROGRAM:ld  PROJECT:dyld-1015.7
BUILD 18:48:43 Aug 22 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
Library search paths:
Framework search paths:
ilg@wksi ~ % uname -a
Darwin wksi.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:27 PDT 2023; root:xnu-10002.41.9~6/RELEASE_X86_64 x86_64
ilg@wksi ~ % /usr/bin/ld --version
ld: unknown option: --version

Was this problem addressed in the latest release?

Thanks for the conclusion. Happy it worked for you.

Apple linker not supported? Huh…

Your apple linker is from a 2009 operating system which was last updated in 2012. The Apple linker obviously has changed output since 2012. Not sure what the point of your comment is 😃.

You can also see that I get the same error from version 609 of the linker (as I shown you above), which was released on March 2021: https://github.com/apple-opensource/ld64/tags

The point of my comment is that old or new Apple ld is failing for me, and if I’m at fault somehow I’d like to be shown how.