[cfe-dev] clang++ as drop-in g++ replacement

Jeenu Viswambharan via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 6 01:52:52 PST 2015


I'm trying to use clang++ as drop-in replacement for G++ in a project.
I'm compiling for AArch64. When linking, clang seems to invoke the
native (x86) /usr/bin/ld instead of the one from AArch64 GCC suite. The
clang link command line looks like:

clang++ -target aarch64-linux-gnu -v \
  -gcc-toolchain /path/to/aarch64/gcc \   # Root of my AArch64 tool chain
  --sysroot=/path/to/aarch64/gcc/libc \   # From aarch64-linux-gnu-g++
-print-sysroot
  <some other options> <obj files>

And from the verbose output, I get:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: aarch64--linux-gnu
Thread model: posix
Found candidate GCC installation:
/path/to/aarch64/gcc/lib/gcc/aarch64-linux-gnu/4.9.3
Selected GCC installation: /path/to/aarch64/gcc/lib/gcc/aarch64-linux-gnu/4.9.3
 "/usr/bin/ld" --sysroot=/path/to/aarch64/gcc/aarch64-linux-gnu/libc ...

I don't get why clang got around choosing the native linker. The link
fails for obvious reasons that object files are AArch64 ELF.

The inferred target looks suspicious; so I changed it to just aarch64.
Even then, clang ends up invoking native linker.

Please advise.

PS: Please note that all these are from a legacy script that I'm
working on. I'm a rather novice clang user, and probably don't yet
know what I'm doing!

-- 
Jeenu



More information about the cfe-dev mailing list