下了官网的clang+llvm-3.1-i386-mingw32-EXPERIMENTAL.tar.bz2,解压后将bin添加到环境变量path中。采用标准mingw32(http://www.mingw.org/)或tdm mingw32(http://tdm-gcc.tdragon.net/)的,只要将其安装到C:\mingw(或在win7下用mklink将C:\mingw指向安装目录),并将C:\mingw\bin添加到环境变量path中就万事大吉了。
若追求新版本而采用下面两种版本MinGW32的
i686-pc-mingw32 从 http://code.google.com/p/mingw-builds/下载
或i686-w64-mingw32从 http://sourceforge.net/projects/mingwbuilds/files/ 下载
就算按上面的方法设置好环境变量path,仍然会得到下面的错误而无法使用
clang test.c
test.c:2:11: fatal error: 'stdio.h' file not found
# include
^
1 error generated.
这是因为clang默认的 MinGW32 头文件搜索路径如下:
Clang works on some mingw32 distributions. Clang assumes directories as below;
C:/mingw/include
C:/mingw/lib
C:/mingw/lib/gcc/mingw32/4.[3-5].0/include/c++
为了使Clang适应 i686-pc-mingw32 和 i686-w64-mingw32的目录设置。需要修改llvm-src-path\tool\clang\lib\\Frontend\InitHeaderSearch.cpp并重新编译。
改动如下红色部分:
…
/// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
/// libstdc++.
void AddMinGWCPlusPlusIncludePaths(StringRef Base,
StringRef Arch,
StringRef Version);
void AddMinGWCPlusPlusIncludePaths2(StringRef Base,
StringRef Arch,
StringRef Version);
…
void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths2(StringRef Base,
StringRef Arch,
StringRef Version) {
AddPath(Base + "/include/c++/" + Version,
CXXSystem, true, false, false);
AddPath(Base + "/include/c++/" + Version + "/" + Arch,
CXXSystem, true, false, false);
AddPath(Base + "/include/c++/backward/" + Version,
CXXSystem, true, false, false);
}
…
void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
…
AddPath("c:/mingw/include", System, true, false, false);
//i686-pc-mingw32
AddPath("c:/mingw/i686-pc-mingw32/include", System, true, false, false);
//i686-w64-mingw32
AddPath("c:/mingw/i686-w64-mingw32/include", System, true, false, false);
…
void InitHeaderSearch::
AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
…
case llvm::Triple::MinGW32:
// mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.4");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.2");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.3");
AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.7.0");
// mingw.org C++ include paths
AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.1");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.7.0");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.3");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.6.1");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
//i686-pc-mingw32
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.7.2");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.7.1");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.7.0");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.6.3");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.6.2");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.6.1");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.5.2");
AddMinGWCPlusPlusIncludePaths2("c:/mingw", "i686-pc-mingw32", "4.5.0");
//i686-w64-mingw32
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.7.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.7.1");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.7.0");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.6.3");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.6.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.6.1");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.5.2");
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "i686-w64-mingw32", "4.5.0");
break;
…
在过了约1小时的编译,新的llvm+clang 3.1浴火重生了!