Search code examples
windowsc++11gccclang++llvm-clang

What do you need to install to use Clang on windows to build c++14 for 64 bit?


UPDATE:

I've written a detailed tutorial that incorporates the top two answers on this question: http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt1/



TL;DR

On Windows, Given the following program:

#include <iostream>

int main()
{
    int arr[] = {1, 2, 3, 4, 5};
    for(auto el : arr)
    {
        std::cout << el << std::endl;
    }
    return 0;
}

I want to be able to do the following:

clang++ hello.cpp -o hello.exe -std=c++14

And get a 64 bit executable that just works. I don't want to have to append a ton of -I includes to tell clang where to find iostream or other standard c++ headers; I don't want to have to link in multiple steps.

I don't care so much about performance, efficiency, what linker is used, etc. I just want to be able to have clang/gcc/whatever set up correctly so that I can use a single, quick and dirty, console command like the one above.

What do I need to install for that to just work?


The Problem

As a predominately mac/linux user I'm used to being able to just use a package manager to install the latest version of clang, which just works.

I'm now trying to set up clang/gnu compiler on windows and it seems to be far more difficult, If only because there is little to no straightforward documentation out there (that I've been able to find)

I've tried to follow this tutorial: https://yongweiwu.wordpress.com/2014/12/24/installing-clang-3-5-for-windows - and was able to use it to get clang to build and link (using gcc 4.8.2), but the resulting binaries were 32 bit.

I've tried installing the latest prebuilt binaries of clang (3.6.2) and the 64 bit version of mingw-w64 (4.9.3 for 64 bit with posix and sjlj for exceptions), and am getting:

hello.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.

Which seems to indicate that clang is not seeing gcc's files. It seems that some versions of LLVM/clang are looking for only certain versions of gcc, but that doesn't seem to be documented anywhere?

Similarly someone mentioned to me on the LLVM IRC that you need to modify clang's driver to look for gcc in certain paths?


What I'm looking for

I'm fine with building LLVM/Clang from source if necessary, but I'm really just looking for clear, step-by-step instructions that allow me to use clang++ as easily as I'm able to do with mac/linux

Something like:

  1. Build this version of LLVM/Clang and place it in that directory
  2. Download and install this version of cygwin (or mingw32 or mingw-w64) and install these packages.
  3. etc..

Solution

  • if you use the upcoming clang 3.7.0, simply set PATH to include mingw-w64's bin, clang will work as you expect