You are not logged in.

#1 2021-07-28 14:09:13

WinLinux1028
Member
Registered: 2021-07-28
Posts: 3

I can't cross compile to aarch64-linux-gnu with clang

I want to use clang and cross compile to aarch64.
I tried, but the error occurs.

[reimu@main Desktop]$ clang --target=aarch64-linux-gnu -fuse-ld=lld -v a.c
clang version 12.0.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/11.1.0
Selected GCC installation: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/clang-12" -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name a.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu generic -target-feature +neon -target-abi aapcs -fallow-half-arguments-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/12.0.1 -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/12.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/reimu/Desktop -ferror-limit 19 -stack-protector 2 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/a-ed514f.o -x c a.c
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/clang/12.0.1/include
 /usr/include
End of search list.
 "/usr/bin/ld.lld" -pie -EL --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/Scrt1.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/crti.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtbeginS.o -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib/../lib64 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/a-ed514f.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtendS.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/crtn.o
ld.lld: error: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtbeginS.o is incompatible with elf64-x86-64
ld.lld: error: /tmp/a-ed514f.o is incompatible with elf64-x86-64
ld.lld: error: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib/../lib64/libgcc_s.so.1 is incompatible with elf64-x86-64
ld.lld: error: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib/../lib64/libgcc_s.so.1 is incompatible with elf64-x86-64
ld.lld: error: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtendS.o is incompatible with elf64-x86-64
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

Last edited by WinLinux1028 (2021-07-28 14:17:41)

Offline

#2 2021-07-28 14:10:53

WinLinux1028
Member
Registered: 2021-07-28
Posts: 3

Re: I can't cross compile to aarch64-linux-gnu with clang

If I execute compile command without  -fuse-ld=lld , this error occurs.

[reimu@main Desktop]$ clang --target=aarch64-linux-gnu -v a.c
clang version 12.0.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib/gcc/aarch64-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib64/gcc/aarch64-linux-gnu/11.1.0
Selected GCC installation: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/usr/bin/clang-12" -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name a.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu generic -target-feature +neon -target-abi aapcs -fallow-half-arguments-and-returns -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/12.0.1 -internal-isystem /usr/local/include -internal-isystem /usr/lib/clang/12.0.1/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/reimu/Desktop -ferror-limit 19 -stack-protector 2 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -o /tmp/a-4bb601.o -x c a.c
clang -cc1 version 12.0.1 based upon LLVM 12.0.1 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/clang/12.0.1/include
 /usr/include
End of search list.
 "/usr/bin/aarch64-linux-gnu-ld" -pie -EL --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/Scrt1.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/crti.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtbeginS.o -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib/../lib64 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../aarch64-linux-gnu/lib -L/usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib /tmp/a-4bb601.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/crtendS.o /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/crtn.o
/usr/bin/aarch64-linux-gnu-ld: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/Scrt1.o: Relocations in generic ELF (EM: 62)
/usr/bin/aarch64-linux-gnu-ld: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/Scrt1.o: Relocations in generic ELF (EM: 62)
/usr/bin/aarch64-linux-gnu-ld: /usr/bin/../lib64/gcc/aarch64-linux-gnu/11.1.0/../../../../lib64/Scrt1.o: error adding symbols: file in wrong format
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

Last edited by WinLinux1028 (2021-07-28 14:18:05)

Offline

#3 2021-07-28 14:14:43

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 3,735

Re: I can't cross compile to aarch64-linux-gnu with clang

Please edit your posts and use [ code ] tags (not quote tags) when posting output. This makes the output easier to read and provides a scroll box for long output.

https://wiki.archlinux.org/title/Genera … s_and_code
https://bbs.archlinux.org/help.php#bbcode

Offline

#4 2021-07-28 14:18:57

WinLinux1028
Member
Registered: 2021-07-28
Posts: 3

Re: I can't cross compile to aarch64-linux-gnu with clang

2ManyDogs wrote:

Please edit your posts and use [ code ] tags (not quote tags) when posting output. This makes the output easier to read and provides a scroll box for long output.

https://wiki.archlinux.org/title/Genera … s_and_code
https://bbs.archlinux.org/help.php#bbcode

OK, I did it.

Offline

#5 2021-11-05 17:26:19

RyanHir
Member
Registered: 2021-11-05
Posts: 1

Re: I can't cross compile to aarch64-linux-gnu with clang

Can you try adding the following argument to your clang command?

--sysroot=/usr/aarch64-linux-gnu

  I was able to get a good build with

clang --target=aarch64-linux-gnu --sysroot=/usr/aarch64-linux-gnu hello.c

Offline

#6 2021-11-05 17:29:06

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,326
Website

Re: I can't cross compile to aarch64-linux-gnu with clang

Dunno about clang but I build for aarch64 like this:

% CARCH=aarch64 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- makepkg -sCAf --noconfirm

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB