I have followed the following step by step guide and I've managed, after a bit of fiddling, to get clang to compile using code:blocks and MinGW. Great, so now I could add the Clang module to eclipse (why have one IDE when you can have four) and start compiling.
I can compile a simple program that doesn't use the standard library but unfortunately when I try to compile this:
#include <iostream> using namespace std; int main() { cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0; }
first of all I get this:
..\src\test.cpp:9:10: fatal error: 'iostream' file not found
so I add the Mingw headers to the include path; then I get this:
'fatal error: 'bits/c++config.h' file not found'
which is weird. Why does MingW work if that file isn't in 'bits/'? Is it built in to the compiler?. Never mind, I find an implementation of it and create the file in 'bits/'.
Then I get a whole storm of errors including strange ones that seem to suggest either clang doesn't implement the preprocessor correctly or else my understanding of the preprocessor is incorrect.
C:\Program Files\CodeBlocks\MinGW\lib\gcc\mingw32\4.4.1\include\c++/cwchar:45:26: error: expected value in expression #if _GLIBCXX_HAVE_WCHAR_H
and many more like that. Should that be
#if defined(_GLIBCXX_HAVE_WCHAR_H)
or
#ifdef _GLIBCXX_HAVE_WCHAR_H?
If they are then the MinGW standard libraries are wrong.
I assume I'm incorrect in assuming that clang can be dropped in to replace gcc and that it is not designed to work with the gnu standard libraries. Any confirmation or denial of this, backed up with evidence would be most welcome!
So, does anybody have a foolproof way to get clang compiling on a Windows PC? There's a dearth of information online regarding clang and especially regarding windows.
I'm really keen to get clang and LLVM working as they sound great from what I've read. Any help would be appreciated.
Thanks.
On Windows, it's easy to install the Clang tools. Just grab the “Clang compiler for Windows,” an optional component of the “Desktop development with C++” workload. This will install everything you need to develop with Clang on Windows. You can also install your own copy of Clang/LLVM or even build it from source.
To configure a Visual Studio project to use Clang, right-click on the project node in Solution Explorer and choose Properties. Typically, you should first choose All configurations at the top of the dialog. Then, under General > Platform Toolset, choose LLVM (clang-cl) and then OK.
Open a terminal window. Enter the command (clang — version) to confirm if the Clang Compilers had already been installed.
How to Install Clang-Format on Windows. Download Clang for Windows (32-bit) or Clang for Windows (64-bit). Install the package and add the path of %LLVM% \bin to your system environment. The shortcut Alter+Shift+F now works in Visual Studio Code for Windows.
There's some instructions for building clang
on this page (hidden in the "Clang Development" part of the sidebar...). For MinGW you want the section called "On Unix-like Systems". The only tricky part is step 5 which tells you how to set up the paths for the C++ standard library. These need to be added into the code in clang/lib/Frontend/InitHeaderSearch.cpp
. On my machine it wound up looking like this
// FIXME: temporary hack: hard-coded paths. AddPath("/usr/local/include", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/mingw32", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include/c++/backward", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../include", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include", System, true, false, false); AddPath("c:/msysgit/mingw/bin/../lib/gcc/mingw32/4.4.0/include-fixed", System, true, false, false);
though I'm not sure all these are needed!
Depending on your version of MinGW
(and thus the version of gcc ported), the headers might be scattered a bit...
In the file clang/lib/Frontend/InitHeaderSearch.cpp
you will find a number of hard-coded paths. The trouble is that each is version specific, so if your version of MinGW is not in there, then feel free to add it (and ask for it to be integrated in Clang's mainline by posting the patch to cfe-commit).
Personally I run it on MinGW/msys with only minor issues (a number of test cases fail because my msys shell mangles the input when there are :
in...), I have not tried using it from CodeBlocks though (I'm used to the command line).
If you wish to help, Takumi is watching over MinGW integration, Francois Pichet is leading the work on compatibility with VC++/MFC headers (ie is the main contributor) and @rubenvb is currently trying to push patches on libc++ to have it working on Windows (libc++ does not compile on Windows yet). The 3 areas are pretty much independent and require different skills and knowledge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With