Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang is not compiling code for platforms other than x86

Tags:

c++

llvm

clang

arm

I'm under Ubuntu 12.04 x86 64 bit, I have compiled a 32 bit version of llvm/clang from the official svn repository successfully.

I'm now trying to compile c++ code for ARM, at this point i don't care about platform versions like armv5 vs armv7a, I'm focusing on how the platform switch works for clang:

llvm-config --targets-built
ARM CellSPU CppBackend Hexagon Mips MBlaze MSP430 NVPTX PowerPC Sparc X86 XCore

but the following command doesn't work

clang++ -arch arm soft.cpp -o soft_ARM

the output is

clang-3: warning: argument unused during compilation: '-arch arm'

I have also tried gcc-like variants or other combinations like -arch=arm, -arch=armv7a, -march=armv5 but nothing seems to work.

After reading some docs i noticed that clang works for ARM only under MAC OS X / Darwin and it's not supposed to work for ARM under other OS.

How i can compile for ARM with clang and what the output of llvm-config --targets-built is really about ?

like image 261
user1797612 Avatar asked Nov 04 '12 18:11

user1797612


People also ask

Is Clang a cross compiler?

On the other hand, Clang/LLVM is natively a cross-compiler, meaning that one set of programs can compile to all targets by setting the -target option.

Does Clang compile C++?

The Clang tool is a front end compiler that is used to compile programming languages such as C++, C, Objective C++ and Objective C into machine code. Clang is also used as a compiler for frameworks like OpenMP, OpenCL, RenderScript, CUDA and HIP.

Is Clang GCC compatible?

The Clang driver is intended to be a production quality compiler driver providing access to the Clang compiler and tools, with a command line interface which is compatible with the gcc driver.

Which is faster GCC or Clang?

GCC does not have this. GCC's PCH mechanism (which is just a dump of the compiler memory image) is related, but is architecturally only able to read the dump back into the exact same executable as the one that produced it (it is not a structured format). Clang is much faster and uses far less memory than GCC.


1 Answers

-arch is darwin-only feature. You should use -target on non-darwin platforms. Alternatively, compile llvm/target specifying target triplet or create a link from clang to -clang. In your case the target triplet would be arm-none-linux-gnueabi

like image 95
Anton Korobeynikov Avatar answered Oct 21 '22 01:10

Anton Korobeynikov