madhur4127
madhur4127

Reputation: 336

force clang to use llvm instead of gcc in linux

How can I make use of llvm as clang backend to compile C++ files without using gcc as clang's backend? I am pretty sure clang is using gcc because

$ clang++ --version
clang version 6.0.1 (tags/RELEASE_601/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

it uses gnu as target instead of llvm. My llvm-config output:

$ llvm-config --version --targets-built
6.0.1
X86

I built both clang and llvm from source using standard options for my build target(X86).

EDIT: I think it is using gcc as backend because this code produces error in online ide but works on my machine with clang++ and g++. Code relies on fact that gcc has implementation of policy based data structures which are not part of standard.

Upvotes: 1

Views: 2572

Answers (1)

JVApen
JVApen

Reputation: 11317

The problem is in the interpretation of the data. The target that clang refers to has to do with the platform for which you are generating code.

  • x86_64 This is a 64 bit processor compatible with Intel/and
  • unknown I'm uncertain about this one, though I believe it specifies more detail about the processor, which ain't available
  • linux You are using a Linux kernel/operation system
  • gnu The object structure should follow the gnu standards, I believe this directly maps on ELF

This will be different if you use BSD or windows as OS, or when your processor is an ARM, Intel 32 bit, Spark ...

The only moment you should be worrying about the target is when you are cross compiling. In other words, if the computer on which you are running the compiler has other requirements for the executable structure than the machine on which you will be running it.

PS: Clang always uses LLVM for it's IR. ignoring the deprecated Clang+C2, it always uses the LLVM optimizer and code generator.

Upvotes: 1

Related Questions