meson icon indicating copy to clipboard operation
meson copied to clipboard

"Unknown compiler" for Android NDK

Open abergmeier opened this issue 4 years ago • 4 comments

Describe the bug When trying to use Android NDK, I only get the error message "Unknown compiler"

Setting MESON_FORCE_BACKTRACE=1 it gives me:

Project name: mesa
Project version: 21.3.0-devel
C compiler for the build machine: cc (gcc 9.3.0 "cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0")
C linker for the build machine: cc ld.bfd 2.34
C++ compiler for the build machine: c++ (gcc 9.3.0 "c++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0")
C++ linker for the build machine: c++ ld.bfd 2.34

meson.build:21:0: ERROR: Unknown compiler(s): [['/user/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android31-clang']]

A full log can be found at /user/build-android-aarch64/meson-logs/meson-log.txt
Traceback (most recent call last):
  File "/usr/bin/meson", line 20, in <module>
    sys.exit(mesonmain.main())
  File "/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py", line 226, in main
    return run(sys.argv[1:], launcher)
  File "/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py", line 217, in run
    return CommandLineParser().run(args)
  File "/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py", line 129, in run
    return options.run_func(options)
  File "/usr/lib/python3/dist-packages/mesonbuild/msetup.py", line 245, in run
    app.generate()
  File "/usr/lib/python3/dist-packages/mesonbuild/msetup.py", line 159, in generate
    self._generate(env)
  File "/usr/lib/python3/dist-packages/mesonbuild/msetup.py", line 176, in _generate
    intr = interpreter.Interpreter(b)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreter.py", line 2167, in __init__
    self.parse_project()
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 397, in parse_project
    self.evaluate_codeblock(self.ast, end=1)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 436, in evaluate_codeblock
    raise e
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 430, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 441, in evaluate_statement
    return self.function_call(cur)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 788, in function_call
    return func(node, posargs, kwargs)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 143, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreterbase.py", line 174, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreter.py", line 2848, in func_project
    self.add_languages(proj_langs, True)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreter.py", line 2951, in add_languages
    success &= self.add_languages_for(args, required, MachineChoice.HOST)
  File "/usr/lib/python3/dist-packages/mesonbuild/interpreter.py", line 2966, in add_languages_for
    comp = self.environment.detect_compiler_for(lang, for_machine)
  File "/usr/lib/python3/dist-packages/mesonbuild/environment.py", line 1587, in detect_compiler_for
    comp = self.compiler_from_language(lang, for_machine)
  File "/usr/lib/python3/dist-packages/mesonbuild/environment.py", line 1559, in compiler_from_language
    comp = self.detect_c_compiler(for_machine)
  File "/usr/lib/python3/dist-packages/mesonbuild/environment.py", line 1091, in detect_c_compiler
    return self._detect_c_or_cpp_compiler('c', for_machine)
  File "/usr/lib/python3/dist-packages/mesonbuild/environment.py", line 1088, in _detect_c_or_cpp_compiler
    self._handle_exceptions(popen_exceptions, compilers)
  File "/usr/lib/python3/dist-packages/mesonbuild/environment.py", line 743, in _handle_exceptions
    raise EnvironmentException(errmsg)
mesonbuild.mesonlib.EnvironmentException: Unknown compiler(s): [['/user/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android31-clang']]

To Reproduce Uses latest mesa source and latest Android NDK.

Expected behavior Should simply use the scripts provided by Android NDK. Or rather if it encounters an error it should spill as much internal information as possible. The current behavior is not optimal for providing proper bug reporting.

system parameters

  • Is this a cross build? yes
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) Ubuntu 20.04
  • what Python version are you using e.g. 3.8.0 3.8.10
  • what meson --version 0.53.2

abergmeier avatar Aug 26 '21 07:08 abergmeier

It is strange to me that the compiler itself is in a list.

tristan957 avatar Aug 26 '21 18:08 tristan957

I'm having this same issue trying to cross-compile for arm64 on:

  • OS: Ubuntu 20.04
  • Meson: 0.58.0
  • Python: 3.8.10

Here's the trace:

$ meson build --cross cross_file_android_arm64_28.txt 
The Meson build system
Version: 0.58.0
Source dir: /workspaces/pntos-for-android
Build dir: /workspaces/pntos-for-android/build
Build type: cross build
Project name: pntos-for-android
Project version: 0.0.1-dev

meson.build:1:0: ERROR: Unknown compiler(s): [['/workspaces/pntos-for-android/android-toolchain-arm64-28/bin/aarch64-linux-android-clang']]

A full log can be found at /workspaces/pntos-for-android/build/meson-logs/meson-log.txt
Traceback (most recent call last):
  File "/usr/local/bin/meson", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/mesonmain.py", line 231, in main
    return run(sys.argv[1:], launcher)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/mesonmain.py", line 222, in run
    return CommandLineParser().run(args)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/mesonmain.py", line 134, in run
    return options.run_func(options)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/msetup.py", line 281, in run
    app.generate()
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/msetup.py", line 184, in generate
    self._generate(env)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/msetup.py", line 201, in _generate
    intr = interpreter.Interpreter(b)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreter/interpreter.py", line 258, in __init__
    self.parse_project()
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 640, in parse_project
    self.evaluate_codeblock(self.ast, end=1)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 680, in evaluate_codeblock
    raise e
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 673, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 686, in evaluate_statement
    return self.function_call(cur)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 1065, in function_call
    return func(node, func_args, kwargs)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 212, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreterbase.py", line 243, in wrapped
    return f(*wrapped_args, **wrapped_kwargs)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreter/interpreter.py", line 1054, in func_project
    self.add_languages(proj_langs, True, MachineChoice.HOST)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreter/interpreter.py", line 1167, in add_languages
    success = self.add_languages_for(args, required, for_machine)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/interpreter/interpreter.py", line 1199, in add_languages_for
    comp = self.environment.detect_compiler_for(lang, for_machine)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/environment.py", line 2031, in detect_compiler_for
    comp = self.compiler_from_language(lang, for_machine)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/environment.py", line 2003, in compiler_from_language
    comp = self.detect_c_compiler(for_machine)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/environment.py", line 1491, in detect_c_compiler
    return self._detect_c_or_cpp_compiler('c', for_machine)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/environment.py", line 1488, in _detect_c_or_cpp_compiler
    self._handle_exceptions(popen_exceptions, compilers)
  File "/usr/local/lib/python3.8/dist-packages/mesonbuild/environment.py", line 1046, in _handle_exceptions
    raise EnvironmentException(errmsg)
mesonbuild.mesonlib.universal.EnvironmentException: Unknown compiler(s): [['/workspaces/pntos-for-android/android-toolchain-arm64-28/bin/aarch64-linux-android-clang']]

Here's cross_file_android_arm64_28.txt:

[host_machine]
system = 'android'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

[built-in options]
c_args = ['-I/workspaces/android-arm64-28/include']
c_link_args = ['-L/workspaces/android-arm64-28/lib64',
               '-fuse-ld=gold']

[properties]
growing_stack = true

[binaries]
c = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-clang'
cpp = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-clang++'
ar = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-ar'
as = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-as'
ld = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-ld'
ranlib = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-ranlib'
strip = '/workspaces/android-toolchain-arm64-28/bin/aarch64-linux-android-strip'
pkgconfig = '/workspaces/android-arm64-28/bin/pkg-config'

danielcjacobs avatar Mar 02 '22 01:03 danielcjacobs

I solved by installing libncurses5:

sudo apt install libncurses5

danielcjacobs avatar Mar 02 '22 01:03 danielcjacobs

Should simply use the scripts provided by Android NDK. Or rather if it encounters an error it should spill as much internal information as possible. The current behavior is not optimal for providing proper bug reporting.

Spilling internal details doesn't necessarily mean making it hard to read the scrollback in your terminal. This is why meson prints:

A full log can be found at /user/build-android-aarch64/meson-logs/meson-log.txt

Forcing a backtrace isn't very helpful in this case. It lets you see the call stack of the meson codebase w.r.t. where the error was raised, which is definitely helpful in certain scenarios, but the build log containing the debug info should be the first thing you check.

eli-schwartz avatar Sep 01 '24 05:09 eli-schwartz

Any updates on it? Meson fails at linker detection

Detecting linker via: `/opt/android-ndk-r27d/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android35-clang -Wl,--version` -> 1
stderr:
clang-18: error: unable to execute command: posix_spawn failed: Exec format error
clang-18: error: linker command failed with exit code 1 (use -v to see invocation)

aniam0n avatar Nov 07 '25 02:11 aniam0n