Skip to content
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

How to use meson with an Android toolchain? #13999

Open
criatura2 opened this issue Dec 11, 2024 · 1 comment
Open

How to use meson with an Android toolchain? #13999

criatura2 opened this issue Dec 11, 2024 · 1 comment

Comments

@criatura2
Copy link

Hi, I am trying to build dav1d for Android and I am running in the following error

$ meson setup --prefix=...  --libdir=...  --default-library=static --cross-file meson-cross-file.txt path
The Meson build system
Version: 1.6.0
Source dir: ...
Build dir: ...
Build type: cross build
Project name: dav1d
Project version: 0.9.0
C compiler for the host machine: /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/clang (clang 17.0.2 "Android (11349228, +pgo, +bolt, +lto, -mlgo, based on r487747e) clang version 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362)")
C linker for the host machine: /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/clang ld.lld 17.0.2
Compiler for language c for the build machine not found.
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: aarch64
Host machine cpu: aarch64
Target machine cpu family: aarch64
Target machine cpu: aarch64
Run-time dependency threads found: YES
Checking for function "clock_gettime" : NO
Library rt found: NO
Checking for function "clock_gettime" with dependency -lrt: NO (cached)

../../dav1d-src/meson.build:142:12: ERROR: Problem encountered: clock_gettime not found

A full log can be found at path/meson-log.txt

The meson-log.txt file contains further information

Using cached compile:
Cached command line:  /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/clang .../_deps/dav1d-build/Debug/meson-private/tmpaacak3kg/testfile.c -o .../_deps/dav1d-build/Debug/meson-private/tmpaacak3kg/output.exe --sysroot=/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -std=c99 -D_GNU_SOURCE 

Code:
 #include <time.h>
        int main(void) {

        /* With some toolchains (MSYS2/mingw for example) the compiler
         * provides various builtins which are not really implemented and
         * fall back to the stdlib where they aren't provided and fail at
         * build/link time. In case the user provides a header, including
         * the header didn't lead to the function being defined, and the
         * function we are checking isn't a builtin itself we assume the
         * builtin is not functional and we just error out. */
        #if !0 && !defined(clock_gettime) && !0
            #error "No definition for __builtin_clock_gettime found in the prefix"
        #endif

        #ifdef __has_builtin
            #if !__has_builtin(__builtin_clock_gettime)
                #error "__builtin_clock_gettime not found"
            #endif
        #elif ! defined(clock_gettime)
            __builtin_clock_gettime;
        #endif
        return 0;
        }
Cached compiler stdout:
 
Cached compiler stderr:
 In file included from .../_deps/dav1d-build/Debug/meson-private/tmpaacak3kg/testfile.c:1:
In file included from /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/time.h:37:
In file included from /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/time.h:33:
In file included from /opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/sys/types.h:36:
/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
         ^~~~~~~~~~~~~
1 error generated.

The meson config file looks like this

[binaries]
c = '/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/clang'
cpp = '/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++'
ar = '/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'

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

[built-in options]
c_args = [ '--sysroot=/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot' ]
c_link_args = [ '--sysroot=/opt/android/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/sysroot' ]

Apparently, meson shouldn't be trying to link with -lrt on Android: https://code.videolan.org/videolan/dav1d/-/merge_requests/854.

Any idea about how to fix this? Thanks.

@sfan5
Copy link

sfan5 commented Dec 12, 2024

here's an example crossfile for Android cross-compilation:

[binaries]
c = 'aarch64-linux-android21-clang'
cpp = 'aarch64-linux-android21-clang++'
ar = 'llvm-ar'
nm = 'llvm-nm'
strip = 'llvm-strip'
pkgconfig = 'pkg-config'
pkg-config = 'pkg-config'
[host_machine]
system = 'android'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

You will need to add the .../toolchains/llvm/prebuilt/linux-x86_64/bin folder to your PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants