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!
-
You should be able to get away with defining the envvar `CC=clang` and `CXX=clang++` when you run `configure` – slugonamission Sep 18 '12 at 14:52
-
If that isn't pure, wouldn't clang built by another clang which was build by something else (presumably, otherwise where does that magically come from?) still be impure? – Grizzly Sep 18 '12 at 15:27
-
2@delnan: "pure" means "self-hosted" I think. If the clang1 is built by MinGW, then clang2 is build by clang1 and so on. If the executable on step N coincides with the executable on the step N-1, it is "pure". Just a joke, of course :) – Viktor Latypov Sep 18 '12 at 15:59
-
1This could have been called *How to bootstrap clang*. – Benjamin Bannier Sep 21 '12 at 10:17
-
In [this question](https://stackoverflow.com/questions/39716684/) I completely described the process of "bootstrapping". – Tomilov Anatoliy Jan 28 '18 at 09:33
3 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.

- 14,749
- 1
- 53
- 76
-
1I'm trying to build LLVM with an existing local build of clang in $HOME. I tried CC=$/HOME/llvm_build/bin/clang CXX=..... cmake ../llvm_src -G Ninja, along with enabling LLVM_ENABLE_LLD. The build (somehow) still uses /usr/bin/cc and /usr/bin/c++, and thus results in an error. How should I resolve this ? – kesari Feb 27 '17 at 05:58
-
Does clang come with make? Or do you have to use Mingw32-make on Windows? – Post Self Mar 28 '17 at 13:08
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

- 536
- 1
- 6
- 16
-
-
just use cmake -DCMAKE_C_COMPILER=$(which clang) -DCMAKE_CXX_COMPILER=$(which clang++) $LLVM_SRC_DIR # -G Ninja – f3xy Feb 28 '19 at 19:54
When making clang with clang, you will coincide with the already existing definitions of builtin functions and those which yet to be defined again - the compiler gets into troubles of doubled consciousness!!! I've got the next:
clang/Basic/BuiltinsX86.def:1907:1: note: previous definition is here TARGET_HEADER_BUILTIN(_ReadWriteBarrier, "v", "nh", "intrin.h", ALL_MS_LANGUAGES, "")
clang\CodeGen\code\CGBuiltin.cpp:638:1: error: reference to '_bittest' is ambiguous BitTest BitTest::decodeBitTestBuiltin(unsigned BuiltinID) { ^ include\winnt.h:2236:17: note: expanded from macro 'BitTest' #define BitTest _bittest ^ include\psdk_inc/intrin-impl.h:1707:16: note: candidate found by name lookup is '_bittest' __buildbittest(_bittest, __LONG32, "l", "I") ^ clang\CodeGen\code\CGBuiltin.cpp:620:8: note: candidate found by name lookup is '(anonymous namespace)::_bit test' struct BitTest { ^ include\winnt.h:2236:17: note: expanded from macro 'BitTest' #define BitTest _bittest ^ clang\CodeGen\code\CGBuiltin.cpp:696:45: error: reference to '_bittest' is ambiguous BitTest BT, ^ include\winnt.h:2236:17: note: expanded from macro 'BitTest' #define BitTest _bittest ^ include\psdk_inc/intrin-impl.h:1707:16: note: candidate found by name lookup is '_bittest' __buildbittest(_bittest, __LONG32, "l", "I")
And so on and on ...
-
1Are you trying to say that it's impossible? (I highly doubt so.) Or are you asking for help with your errors? If so, delete this and repost it using the "ask question" button above. – HolyBlackCat Jul 21 '22 at 19:37
-
This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32304475) – Nol4635 Jul 25 '22 at 22:11