Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build clang with clang?

Tags:

c++

c

clang

I allready build clang(3.2) with MSVC and MinGW succesfully. But I think it's not the "purely" clang. So could someone give me some instructions or materials about how to use clang to build clang(Windows/Linux)? And could we use clang indepently(Not depent on GCC or MSVC). Thanks all!

like image 227
sunny2016 Avatar asked Sep 18 '12 14:09

sunny2016


People also ask

Can Clang cross compile?

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.

How do I compile with Clang ++?

2.4. To compile a C++ program on the command line, run the clang++ compiler as follows: $ scl enable llvm-toolset-6.0 'clang++ -o output_file source_file ...' This creates a binary file named output_file in the current working directory. If the -o option is omitted, the clang++ compiler creates a file named a.

Can you compile GCC with Clang?

GCC supports languages that clang does not aim to, such as Java, Ada, FORTRAN, etc. GCC front-ends are very mature and already support C++. clang's support for C++ is nowhere near what GCC supports.


2 Answers

Well get an older version of clang like 3.1. (You can pretty much install any version that comes precompiled for your OS)

Get the sources for a newer version like 3.2.

Then (i like cmake+ninja ( http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html))

if you unpacked llvm source to ~/llvm_source/llvm

cd ~/llvm_source
mkdir build
cd build
CXX=clang++ CC=clang cmake -G Ninja ../llvm -DCMAKE_BUILD_TYPE=Release
ninja

If you want it for make

CXX=clang++ CC=clang cmake ../llvm -DCMAKE_BUILD_TYPE=Release
make

Thats it.

Have fun.

like image 78
RedX Avatar answered Sep 26 '22 01:09

RedX


The current method (as of 27th Feb 17') seems to be as follows,

cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++  $LLVM_SRC_DIR # -G Ninja

Where CMAKE_C_COMPILER and CMAKE_CXX_COMPILER are CMake variables define by -D. Somehow, these variables don't appear in llvm_src/CMakeLists.txt

like image 36
kesari Avatar answered Sep 23 '22 01:09

kesari