Building Clang on MinGW

Hello all :slight_smile:

Since I don't have a proper Unix system yet, and since Visual Studio is such a pain when it comes to Clang, I decided to try out MinGW.

I've properly installed MinGW, and I've followed the instructions at:

I decided to begin simple, using `make` instead of `cmake`, but it fails:

>> make[1]: Entering directory `/d/llvm-build/tools/llvm-
>> llvm[1]: Regenerating LibDeps.txt.tmp
>> 'd:' n'est pas reconnu en tant que commande interne ou externe, un programme executable ou un fichier de commandes.
>> nm failed at d:/llvm/utils/ line 230.

(the French line means that apparently the script gets a "d:" command to execute, which probably stems from a path issue, since paths on Windows begin by the drive letter followed by a colon, though I don't understand how this could be interpreted as a command instead of a path...)

The script line is:

>> close UNDEFS or die "nm failed";

which does correspond to the error message... however I am no perl user... so I don't really understand what's going on here.

I'd appreciate some pointers from people using MinGW :slight_smile:


You should really use CMake to build on mingw:

cmake path/to/llvm/source -G"MinGW Makefiles"

Note that you'll need "mingw32-make.exe" installed in the mingw/bin folder.

Alternatively, install MSYS and run CMake from the msys bash shell:

cmake path/to/llvm/source -G"MSYS Makefiles"

It might be possible to do (from MSYS):


But it surely will be slower than running CMake.

Hope this helps!

Hello Ruben,

You should really use CMake to build on mingw:

This is not a strict requirement. Everything works fine out of the box
with just configure + make inside msys shell w/o cmake.

I know, it’s only a recommendation, because CMake is just faster than MSYS. But it also works, yes.



As I succeeded in building clang, I’ve tested the compiled binary, and it seems I have (yet again) some environment hiccups (mind you “only” 23 unexpected failures)

There seems to be some shell issues:

FAIL: Clang :: Preprocessor/cxx_oper_spelling.cpp (1700 of 2898)
D:/llvm-cmake/bin/.\clang.EXE -cc1 -E D:\llvm\tools\clang\test\Preprocessor\cxx_oper_spelling.cpp | grep ‘a: “and”’

Command 1 Stderr:
/usr/bin/grep: Trailing backslash

Even though when I used the command myself in MSYS everything works fine (though I do have to transform it before), so I was wondering if I should run the tests from the MSYS command line or from the basic Windows console (by the way, the executable name is wrong here, it’s .exe)

I have had some issues with missing headers, such as:

<stdlib.h> // located in /mingw/include

So I’ve modified /d/llvm/tools/clang/lib/Frontend/InitHeaderSearch.cpp

Index: lib/Frontend/InitHeaderSearch.cpp

test_result.txt (64.9 KB)