Using Clang on Mingw 64bit
c++, clang, gcc, mingw, qmake
Solution
Check this link: https://web.archive.org/web/20140301212210/http://www.bencode.net/blog/2012/10/20/clangonwindows/
It is a tutorial on installation steps for getting a functional Clang++ build running on Windows 8 and MinGW. Windows 8 and Windows 7 share a lot in common, this tutorial can be used to accomplish your task.
==================================================
Step 1
Install MinGW. Using mingw-get-inst-20120426.exe go with the pre-packaged repository catalogues, which bundles in GCC 4.6.1 as opposed to 4.7.x, which at the time of writing Clang does not support seamlessly. You will need the C Compiler, C++ Compiler, MSYS Basic System and MinGW Developer Toolkit MinGW packages.
Step 2
Python 2.x. Install the Python Interpreter and Libraries into c:\MinGW\bin.
Step 3
Install Subversion. I went with the Subversion 1.7.7 (Windows 64-bit) package from CollabNet.
Checkout LLVM:
cd C:\mingw\msys\1.0 mkdir src cd src svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
Checkout Clang:
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ../..
Checkout Compiler-RT:
cd llvm/projects
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
cd ../..
Step 4
C++ headers and libraries. Clang will attempt to automatically probe MinGW’s directory structure for set of supported libstdc++ paths. For 32-bit i686-w64-mingw32, and 64-bit x86_64-w64-mingw32, Clang assumes as below:
- some_directory/bin/gcc.exe
- some_directory/bin/clang.exe
- some_directory/bin/clang++.exe
- some_directory/bin/../include/c++/GCC_version
- some_directory/bin/../include/c++/GCC_version/x86_64-w64-mingw32
- some_directory/bin/../include/c++/GCC_version/i686-w64-mingw32
- some_directory/bin/../include/c++/GCC_version/backward
- some_directory/bin/../x86_64-w64-mingw32/include
- some_directory/bin/../i686-w64-mingw32/include
- some_directory/bin/../include
This probing logic can be found in InitHeaderSearch.cpp located here (line 374 as of writing this):
- C:\mingw\msys\1.0\src\llvm\tools\clang\lib\Frontend\InitHeaderSearch.cpp
Ensure that the version of gcc that your MinGW installer used, matches a supported version (e.g. 4.6.2 is my case) by looking here C:\mingw\lib\gcc\mingw32\4.6.2.
If your version of gcc does not seem to be supported automatically, Clang will be usable to resolve standard libraries and headers – you want this. Some popular way to help Clang find these (if it doesn’t already):
- Specify the --with-gcc-toolchain configure option (prior to build) to tell Clang where the gcc containing the desired libstdc++ is installed.
- Create a symbolic link, e.g. if you have 4.7.2 and only upto 4.7.0 is in the auto probe logic, create a 4.7.0 symbolic link to 4.7.2.
- Modify InitHeaderSearch.cpp to your specific environment prior to building Clang.
Step 5
Build. Using a MinGW shell. Credits to Pete for this.
cd /src
mkdir build
cd build
export CC=gcc
export CXX=g++
../llvm/configure --disable-docs --enable-optimized --enable-targets=x86,x86_64 --prefix=/mingw
make
make install
Credit for original work: Posted by Ben Simmonds Oct 20th, 2012
Problem
I want to have clang in addition to GCC in a MinGW-64bit environment on Windows 7, both using the standard library from gcc. I'm using gcc_x64_4.8.1_win32_seh_rev1 and Qt from http://sourceforge.net/projects/mingwbuilds/. I built clang 3.3 in this environment, without any flags (just getting around the `HAVE_EHTABLE_SUPPORT` compile problem). I use a qmake build process and the project file has these lines additionally for clang (just release mode): ``` QMAKE_CC = clang QMAKE_CXX = clang++ QMAKE_CXXFLAGS_RELEASE += -Wno-ignored-attributes QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1" QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++" QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++/x86_64-w64-mingw32" QMAKE_CXXFLAGS_RELEASE += -I"C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/x86_64-w64-mingw32/include" ``` Compiling gets down to: ``` C:/tc/gcc_x64_4.8.1_win32_seh_rev1/mingw64/lib/gcc/x86_64-w64-mingw32/4.8.1/include/c++\bits/random.h:106:26: error: __int128 is not supported on this target { typedef unsigned __int128 type; }; ^ ``` Searching the internet gave references to _mingw.h, but I don't know what is wrong there: ``` #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) && \ !defined(__SIZEOF_INT128__) /* clang >= 3.1 has __int128 but no size macro */ #define __SIZEOF_INT128__ 16 #endif ```