14

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
Waqar
  • 8,558
  • 4
  • 35
  • 43
Mike M
  • 2,263
  • 3
  • 17
  • 31
  • 2
    See this thread how to get clang working on windows: http://stackoverflow.com/questions/6525245/getting-clang-to-work-on-windows especially this post: http://stackoverflow.com/a/6525707/1392778 . Btw, compile clang in a 32 bit environment, as clang doesn't support exception handling on 64bit windows yet, which means you need to build everything with -fno-exceptions... – Thomas Jun 30 '13 at 11:55
  • Well I tried it, and I get now to the same problem but without including the paths to the standard library. So the error is still: __int128 is not supported on this target. The point is not, that the standard library of gcc is not found, the problem is, that it seems not to work with clang (at least gcc version 4.8.1 and clang 3.3). – Mike M Jul 01 '13 at 11:39
  • I am using clang-3.3 bundled with tdm mingw 4.7.1 and building bits/random.h works fine for me. So you may consider trying 4.7.x instead. – Thomas Jul 01 '13 at 12:46
  • The build of _rubenvb_ has worked for me other time [rubenvb SourceForge](http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/). The last builds are from clang 3.3, download GCC and updated with clang files. – NetVipeC Jul 16 '14 at 19:32

2 Answers2

8

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

Samuel
  • 81
  • 1
  • 6
  • Thanks for posting your answer! Please note that you should post the essential parts of the answer here, on this site, or your post risks being deleted [See the FAQ where it mentions answers that are 'barely more than a link'.](http://stackoverflow.com/faq#deletion) You may still include the link if you wish, but only as a 'reference'. The answer should stand on its own without needing the link. – Taryn Oct 06 '14 at 11:22
  • @bluefeet And this was a very good advice that was not followed: now the link is dead, and the answer is frustrating noise. – Ad N Aug 20 '15 at 07:27
  • @AdN The link has been updated with a version from the internet archive. – Taryn Aug 20 '15 at 10:43
  • @bluefeet Thank you ! – Ad N Aug 20 '15 at 11:02
1

Instead of doing everything manually, use llvm-mingw project:

https://github.com/mstorsjo/llvm-mingw

Which (at time of writting) has ready to use binary releases:

https://github.com/mstorsjo/llvm-mingw/releases

Top-Master
  • 7,611
  • 5
  • 39
  • 71