Skip to content

Build LLVM [3.2, 3.6] with MinGW32 and MSYS

valtron edited this page Oct 17, 2015 · 1 revision
  • Install MinGW
  • Add C:/MinGW/bin, C:/MinGW/msys/1.0/bin to your path
  • Download llvm source into llvm.src
  • mkdir llvm.build
  • If you also want to build clang/++ there are some changes that need to be made to the code (see here)
    • Open llvm-src/tools/clang/lib/Frontend/InitHeaderSearch.cpp
    • Go to around line 388
    • Check if the version of gcc that you are using with mingw has been added to the include search paths
    • If not add (for example if gcc is 4.7.2):
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.2");
  • If you're building LLVM < 3.3:
    • to fix a later issue with llvm-config, do this
  • If you're building LLVM 3.6 and you use python 3 (bug #22976):
    • change line 829 of Makefile.rules to wrap the print arg with parens; i.e.
ECHOPATH := $(Verb)$(PYTHON) -u -c "import sys;print(' '.join(sys.argv[1:]))"
  • Open the windows command line or msys (but not the msys bundled with msysgit, if you have it!) and cd into:
    • If building LLVM 3.3, cd into llvm.src; I could only get in-source build to work. Trying to do it out-of-source seems to work, except make install doesn't copy over the include files
    • for LLVM >= 3.4, out-of-source builds work, so cd into llvm.build
  • Run sh ../llvm.src/configure --prefix=C:/LLVM/llvm-{version} --enable-pic --enable-optimized --disable-docs --enable-targets=x86,x86_64,cpp
    • (for in-source build, do sh configure ... instead)
    • --prefix MUST use forward slashes (otherwise you'll run into escape issues during make)
    • --disable-docs because "groff" isn't present in MinGW
    • --enable-targets because I only need x86; cpp is useful for seeing C++ API calls that produce a given IR using llc -O0 -march=cpp file.ir
  • run make all; should have no problems
  • open mingw's msys (not msysgit!) and run make install; should work; if you get a problem about it not being able to create Intrinsics.gen, it's because doing an out-of-source build doesn't work for some reason; do in-source instead
  • LLVM should now be built. Add C:\LLVM\llvm-{version}\bin to your path.

At this point, you should be able to compile, link and run the Kaleidoscope example.