Can I build the LLVM and clang from source code on cygwin?
How long to build LLVM and Clang? Because I try to build them on VirtualBox, it takes about 2 hours.
Can I build the LLVM and clang from source code on cygwin?
How long to build LLVM and Clang? Because I try to build them on VirtualBox, it takes about 2 hours.
Having spent some amount of effort on this, I figure it might be worthwhile to share some of my findings. I managed to build Clang + LLVM 3.4 on Cygwin 1.7.28 (x86).
A recent update to Cygwin seems to have broken one of the system headers used by Clang. An incomplete patch was provided on the Cygwin mailing list. Here's the full patch.
Clang++ (as of 3.4) still hardcodes the include directories for the C++ standard library (it relies on the ones provided by GCC). If the paths are incorrect (as is often the case on Cygwin), you'll encounter issues when including any C++ header (such as <iostream>
). Two possible ways to fix this:
You can add the correct paths to the code. This is rather inflexible since you'd have to recompile Clang++ every time this changes and this takes a long time on Cygwin. If you want to do this, you can find the code at clang/lib/Frontend/InitHeaderSearch.cpp
on line 389.
Alternatively, you can create a symbolic link where Clang expects them.
Identify the directories searched by Clang++ by executing:
echo | clang++ -v -x c++ -
You should find something along the lines of
ignoring nonexistent directory "/usr/lib/gcc/i686-pc-cygwin/X.Y.Z/include/c++"
There'll probably be several different version numbers X.Y.Z
. Pick any of them, and then create a symbolic link to the correct location:
ln -s A.B.C /usr/lib/gcc/i686-pc-cygwin/X.Y.Z
where A.B.C
is the version of GCC that's currently installed.
If you want colored error messages from Clang, be sure to install the ncurses development package (libncurses-devel
) with Cygwin Setup beforehand. Without it, Clang will fallback to its colorless mode because LLVM wouldn't be able to detect whether the terminal supports colors.
You can still force colors to appear with -fcolor-diagnostics
, but GCC's linker will choke on this flag, which makes it very inconvenient to use.
This is the easiest (and longest) part, and for the most part everything in LLVM + Clang's documentation applies here.
Download the source. Even if you only need Clang, you'll still need the LLVM source code.
After extracting both Clang and LLVM, move the Clang's directory into the tools
subdirectory of LLVM.
mv clang-X.Y llvm-X.Y/tools/clang
Begin by configuring:
./configure --enable-optimized
Clang prefers to choose itself as the compiler, so if you don't have a working Clang installation yet, use the CC
and CXX
environment variables to force it to use GCC instead.
If everything goes alright, you can start building & installing, which will build both clang and llvm:
make && make install
Clang (x86, x86_64) and LLVM (x86, x86_64) are currently available as Cygwin packages.
Installing the Cygwin package would reduce much of your trouble
Do you want to develop llvm/clang or develop with llvm/clang? For the latter case, why not install llvm-3.1/clang binaries from cygwin repository? They work pretty well on my Windows 7.