How to compile Clang on Windows

前端 未结 4 1442
悲&欢浪女
悲&欢浪女 2020-12-04 06:46

I have been trying to find a way to get Clang working on Windows but am having trouble. I get Clang to compile successfully, but when I try to compile a program I have a bun

4条回答
  •  死守一世寂寞
    2020-12-04 06:57

    Here is what worked in my environment, on Windows 8.1, overall similar to Seth's instruction, but with fresher tools.

    1. I installed MinGW 64 into C:/MinGW, to be precise I've used STL's distro.
    2. I installed Python 3, just took their latest version.
    3. I installed CMake 3.0.2
    4. I forked LLVM and Clang on Github and cloned them to my machine, placing Clang's repo into llvm\tools\clang folder (the structure is described on the official page, they just show examples with svn instead of git).
    5. I created "build" folder next to "llvm" folder, and inside the "build" folder ran this command: cmake -G "MinGW Makefiles" -D"CMAKE_MAKE_PROGRAM:FILEPATH=C:/MinGW/bin/make.exe" -DCMAKE_BUILD_TYPE=Release ..\llvm (for some reason CMake couldn't find the "make" automatically)
    6. Then I ran "make" to actually build. The build took a couple of hours.
    7. After that in another folder I've created 1.cpp, which executes a lambda expression to print "hi":
    #include 
    
    int main() {
        []{ std::cout << "hi"; }();
    }
    
    1. I've also created a cmd file to compile the cpp. Alternatively you can just set the PATH variable properly via other means. Note that GCC vesrion in your MinGW package may be different. Also Clang has some builtin paths it tries, but they are tied to specific GCC versions, and mine was not among them, so I had to provide the include paths explicitly.
    set PATH=/bin;c:/mingw/bin;%PATH% 
    clang++ -std=c++11 1.cpp -o 1.exe -I"C:/MinGW/include"
    -I"C:/MinGW/include/c++/4.9.1" -I"C:\MinGW\include\c++\4.9.1\x86_64-w64-mingw32" -I"C:\MinGW\x86_64-w64-mingw32\include"
    
    1. Running that cmd compiled 1.cpp into 1.exe that printed "hi".

    What did not work:

    1. I've tried building the same llvm+clang sources without MinGW+GCC using the MSVC compiler from VS 2015 CTP. It built Clang successfully, the only difference is that you need to do that from the Developer CMD window, and you'd need to run cmake -G "Visual Studio 12" ..\llvm and then compile the solution in Visual Studio. However, that Clang failed to compile a sample cpp, it complained about "undeclared identifier 'char16_t'" and "__int128 is not supported on this target" within the MinGW standard library headers. If I use clang-cl and MS STL headers it complains about "throw x(y)" specifiers . Maybe I needed to provide some extra keys to the build, but I couldn't get it to work.

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xiosbase(293,4) : error: cannot compile this throw expression yet _THROW_NCEE(failure, "ios_base::eofbit set"); C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xstddef(56,30) : note: expanded from macro '_THROW_NCEE' #define _THROW_NCEE(x, y) throw x(y)

提交回复
热议问题