简体   繁体   中英

Clang and C++11 headers

I'm trying to get Clang to work on Windows, to eventually develop with Qt Creator to see if it's a viable alternative to Visual Studio.

I got LLVM and Clang 3.2 (SVN Revision 163238) to compile using MinGW w64 (mingw-w64-bin_i686-mingw_20111220.zip) and also pointed to gcc's C++ header directories by adding AddMinGWCPlusPlusIncludePaths("D:/Code/mingw/lib/gcc", "x86_64-w64-mingw32", "4.7.0"); to clang/lib/Frontend/InitHeaderSearch.cpp , although I think that might not be the most up-to-date method. Anyway, Clang seems to find most of those headers.

However, when compiling a simple Hello World:

#include <iostream>
int main(int argc, char* argv[])
{
  std::cout << "test\n";
  return 0;
}

using clang++ main.cpp I get this error:

In file included from main.cpp:1:
In file included from D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\iostream:39:
In file included from D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\ostream:39:
In file included from D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\ios:39:
In file included from D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\iosfwd:41:
In file included from D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\postypes.h:41:
D:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++\cwchar:45:10: fatal error:
      'wchar.h' file not found

So, Clang apparently finds several C++ headers including iostream but fails to find wchar.h . Turns out that wchar.h is located in .../include/c++\\tr1 where Clang doesn't look for it. Moving those TR1 headers up one directory doesn't help either.

What did I do wrong here? Is the gcc C++ library not compatible with Clang, since apparently it still hasn't integrated some TR1 libraries into the standard? Where could I get a compatible C++11 library for Clang (for Windows!)?

You've misconfigured/mispatched Clang. You need to also add MinGW-w64 paths, somewhere around where you added your version.

Use the prebuilt version I provide with explanation here: Clang on Windows

I modified Clang to work with the MinGW-w64 headers and GCC 4.6.3 libstdc++ headers and libraries. Currently, it's stuck at version 3.2, but if you apply a similar patch to the sources (of which I unfortunately do not have a patch file) you should be able to use it as well.

The one I provide is just extract, add to PATH, and use. And 32-bit only.

Also note you are using an ancient version of MinGW-w64 GCC, and you should really update that.

Try downloading the "wchar.h" manually and placing it in your local working directory of your visual studio project. Works well for me.

If you pass -nostdinc++ to clang you should be able to point it to the exact configuration of includes with multiple -I switches. Try -nostdsysteminc -nobuiltininc as well.

And -v should show you where and in what order it looks for headers when it compiles:

clang++ -v -nostdinc++ -ID:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++ -ID:/Code/mingw/lib/gcc/x86_64-w64-ming32/4.7.0./include/c++/tr1 foo.cpp

我使用Clang --version 3.4(198054)和mingw-get.exe --version 0.6.2-beta-20131004-1遇到了同样的问题:结果我错误地安装了MinGW:我最初只检查了盒子对于mingw-get.exe包选择对话框中的'mingw-gcc-g ++',稍后添加'mingw32-base'解决了这个wchar_t.h问题:clang ++。exe -std = c ++ 11编译C ++ 11 iostream代码就好了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM