Question regarding cross compilation

87 views
Skip to first unread message

José Lira Junior

unread,
Apr 5, 2024, 1:41:17 PM4/5/24
to android-llvm
Hi.

Does AOSP LLVM toolchain supports cross-compilation?
I'm on a Linux machine trying to use clang to compile to arm64 target, but I'm getting linking errors.

```
~/llvm-toolchain/out/stage2-install/bin/clang -print-targets Registered Targets: aarch64 - AArch64 (little endian) aarch64_32 - AArch64 (little endian ILP32) aarch64_be - AArch64 (big endian) arm - ARM arm64 - ARM64 (little endian) arm64_32 - ARM64 (little endian ILP32) armeb - ARM (big endian) bpf - BPF (host endian) bpfeb - BPF (big endian) bpfel - BPF (little endian) riscv32 - 32-bit RISC-V riscv64 - 64-bit RISC-V thumb - Thumb thumbeb - Thumb (big endian) wasm32 - WebAssembly 32-bit wasm64 - WebAssembly 64-bit x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64
```

Do I need to set any options during the build to allow this?

I also tried to download the NDK for Mac and using the sysroot folder there, but no success either.

Thanks in advance for any assistance.

appujee

unread,
Apr 5, 2024, 6:07:37 PM4/5/24
to José Lira Junior, android-llvm
Yes, it supports cross-compilation.

Can you share your compilation command?
> --
> You received this message because you are subscribed to the Google Groups "android-llvm" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to android-llvm...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/android-llvm/ac96b92f-f5b8-4ab1-9110-a941476fd2bfn%40googlegroups.com.

José Lira Junior

unread,
Apr 5, 2024, 9:08:49 PM4/5/24
to android-llvm
Hi. Sure. This is the command and its output.

```
~/llvm-toolchain/out/stage2-install/bin/clang --sysroot=$HOME/sysroot --target=x86_64-apple-darwin20.5.0 -stdlib=libc++ test.cpp -v
Android (dev, -pgo, -bolt, -lto, -mlgo, based on r487747e) clang version 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /home/jose/llvm-toolchain/out/stage2-install/bin
 "/home/jose/llvm-toolchain/out/stage2-install/bin/clang-17" -cc1 -triple x86_64-apple-macosx11.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=all -ffp-contract=on -fno-rounding-math -funwind-tables=2 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu penryn -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -v -fcoverage-compilation-dir=/home/jose/ndk-passes -resource-dir /home/jose/llvm-toolchain/out/stage2-install/lib/clang/17 -isysroot /home/jose/sysroot -stdlib=libc++ -internal-isystem /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1 -internal-isystem /home/jose/sysroot/usr/local/include -internal-isystem /home/jose/llvm-toolchain/out/stage2-install/lib/clang/17/include -internal-externc-isystem /home/jose/sysroot/usr/include -fdeprecated-macro -fdebug-compilation-dir=/home/jose/ndk-passes -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-361868.o -x c++ test.cpp
clang -cc1 version 17.0.2 based upon LLVM 17.0.2 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/jose/sysroot/usr/local/include"
ignoring nonexistent directory "/home/jose/sysroot/System/Library/Frameworks"
ignoring nonexistent directory "/home/jose/sysroot/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1
 /home/jose/llvm-toolchain/out/stage2-install/lib/clang/17/include
 /home/jose/sysroot/usr/include
End of search list.
In file included from test.cpp:1:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/iostream:43:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/ios:220:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/__ios/fpos.h:14:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/iosfwd:100:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/__mbstate_t.h:29:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/wchar.h:124:
In file included from /home/jose/sysroot/usr/include/wchar.h:33:
In file included from /home/jose/llvm-toolchain/out/stage2-install/bin/../include/c++/v1/stdio.h:108:
In file included from /home/jose/sysroot/usr/include/stdio.h:42:
In file included from /home/jose/sysroot/usr/include/sys/types.h:36:
/home/jose/sysroot/usr/include/linux/types.h:21:10: fatal error: 'asm/types.h' file not found
#include <asm/types.h>
         ^~~~~~~~~~~~~
1 error generated.
```

Stephen Hines

unread,
Apr 5, 2024, 9:14:56 PM4/5/24
to José Lira Junior, android-llvm
On Fri, Apr 5, 2024 at 6:08 PM José Lira Junior <jljun...@gmail.com> wrote:
Hi. Sure. This is the command and its output.

```
~/llvm-toolchain/out/stage2-install/bin/clang --sysroot=$HOME/sysroot --target=x86_64-apple-darwin20.5.0 -stdlib=libc++ test.cpp -v

^ You're attempting to target an apple darwin target, not an Android target. That's not really a supported configuration from this build.

Steve
 

José Lira Junior

unread,
Apr 5, 2024, 10:41:39 PM4/5/24
to android-llvm
Thanks for the clarification.

> That's not really a supported configuration from this build.

So, just to confirm, the issue lies in my attempt to target an Apple Darwin platform using the AOSP LLVM Toolchain or is it a matter of configuring the build process differently?

appujee

unread,
Apr 5, 2024, 10:45:12 PM4/5/24
to José Lira Junior, android-llvm
Apple Darwin requires their own set of sysroot. Those are only available on Apple platforms. You can use xcode for targeting anything Apple.

Reply all
Reply to author
Forward
0 new messages