schumacher574
schumacher574

Reputation: 1129

Does clang cross compilation —sysroot require a cross compiler? Or target arch compiler?

I am attempting to cross compile on host x64 for target arm using llvm / clang. I know a sysroot and gcc-toolchain are required, and their flags point to a gcc compiler for the target platform.

I’m confused whether the gcc toolchain should be one that runs on the target arch? Or should it be a cross toolchain that can run on the host arch but compile for the target arch?

I have cross compiled a simple hello world using a target arch gcc toolchain as the sysroot. But, had to use llvm lld for linking. I believe this may be related to not being able to run the gcc toolchains provided ld?

Upvotes: 0

Views: 2231

Answers (2)

HolyBlackCat
HolyBlackCat

Reputation: 96699

--sysroot doesn't use the compiler at the specified location. (I don't think it uses any executables in there at all.) It primarily uses headers and libraries.

I'm not sure if it would try to use the linker from the sysroot by default or not, but this won't matter if you use -fuse-ld=lld. It seems LLD can link for most common platforms.

E.g. I'm cross-compiling from Linux to Windows using a MinGW sysroot copied from Windows (so none of the executables in it can run on Windows), and Clang is fine with it.

Upvotes: 1

David Grayson
David Grayson

Reputation: 87486

GCC is a compiler and clang is a different compiler. You only need one of the two. You might use GNU binutils to link the output of the compiler, but that is not GCC.

Whatever programs you run during cross compilation must be built for the build system (x64), and be configured to allow targeting the target system (ARM).

P.S. Maybe you should look at my project: https://github.com/DavidEGrayson/nixcrpkgs . It shows how to cross-compile on x64 Linux for ARM Linux using GCC (not clang).

Upvotes: 3

Related Questions