[cfe-dev] Clang on Windows targeting gcc requirements

Yaron Keren yaron.keren at gmail.com
Sat Jul 4 22:30:29 PDT 2015


The attached patch should fix that, please let me know if it works for you.



2015-07-05 0:33 GMT+03:00 Hurcan Solter <hsolter at gmail.com>:

> Yes, upon further inspection, aforementioned patch explicitly adds the
> directories in MinGW::AddClangCXXStdlibIncludeArgs()
> which is distinctly different than mingw-builds.
> With MSYS2 C++ include directories is kept in
> /mingw64/include/c++/${gccver} whereas with mingw-builds
> /mingw64/x86_64-w64-mingw32/include/c++
> is where they are.
>
> Old patch is removed from the MSYS2 packages and a new one is introduced
> after this update but unfortunately it does not handle
> the changes. ( I've added the maintainer of clang at MSYS2 in this
> conversation).
>
> MSYS2 is damn great and convenient to use. I'd very much like to see
> recent version of clang is usable without problems again.
>
>
>
>
>
>
>
>
On Sat, Jul 4, 2015 at 6:40 PM, Yaron Keren <yaron.keren at gmail.com> wrote:

> Hi Hurcan,
>
> clang support the mingw-builds and mingw.org directory structure.
> With the msys2 build, the problem is the missing C++ include directories?
>
> Yaron
>
>
> 2015-07-04 16:41 GMT+03:00 Hurcan Solter <hsolter at gmail.com>:
>
>> I've used to build clang on MSYS2 with older version of this patch at
>> https://github.com/Alexpux/MINGW-packages/blob/master/mingw-w64-clang/clang-mingw-driver.patch
>> <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_Alexpux_MINGW-2Dpackages_blob_master_mingw-2Dw64-2Dclang_clang-2Dmingw-2Ddriver.patch&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=Ix-0aW1nGYMxzuqzb9pdVofsl42YNYgvP3nfa6Vzf8E&e=>
>> and it served me well. this new patch not so much.Below the relevant dumps ;
>>
>> $ g++ -E -x c++ - -v < /dev/null
>> Using built-in specs.
>> COLLECT_GCC=C:\msys2_64\mingw64\bin\g++.exe
>> Target: x86_64-w64-mingw32
>> Configured with: ../gcc-4.9.2/configure --prefix=/mingw64
>> --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32
>> --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
>> --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include
>> --libexecdir=/mingw64/lib --with-gxx-include-dir=/mingw64/include/c++/4.9.2
>> --enable-bootstrap --with-arch=x86-64 --with-tune=generic
>> --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared
>> --enable-static --enable-libatomic --enable-threads=posix --enable-graphite
>> --enable-fully-dynamic-string --enable-libstdcxx-time=yes
>> --disable-libstdcxx-pch --disable-libstdcxx-debug
>> --enable-cloog-backend=isl --enable-version-specific-runtime-libs
>> --disable-cloog-version-check --disable-isl-version-check --enable-lto
>> --enable-libgomp --disable-multilib --enable-checking=release
>> --disable-rpath --disable-win32-registry --disable-nls --disable-werror
>> --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64
>> --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64
>> --with-cloog=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project'
>> --with-bugurl=http://sourceforge.net/projects/msys2
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__sourceforge.net_projects_msys2&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=qxch1gn6dUS6rczZ8OX27JDQX2SAixXM5TJTJug9FhI&e=>
>> --with-gnu-as --with-gnu-ld
>> Thread model: posix
>> gcc version 4.9.2 (Rev5, Built by MSYS2 project)
>> COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mtune=generic'
>> '-march=x86-64'
>>  C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/cc1plus.exe
>> -E -quiet -v -iprefix
>> C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/ -D_REENTRANT -
>> -mtune=generic -march=x86-64
>> # 1 "<stdin>"
>> # 1 "<built-in>"
>> # 1 "<command-line>"
>> # 1 "<stdin>"
>> ignoring duplicate directory
>> "C:/msys2_64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.9.2/include"
>> ignoring nonexistent directory "C:/msys64/mingw64/include"
>> ignoring nonexistent directory "/mingw64/include"
>> ignoring duplicate directory
>> "C:/msys2_64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed"
>> ignoring duplicate directory
>> "C:/msys2_64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include"
>> ignoring nonexistent directory
>> "C:/msys64/mingw64/x86_64-w64-mingw32/include"
>> #include "..." search starts here:
>> #include <...> search starts here:
>>  C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include
>>
>>  C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../include
>>  C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/include-fixed
>>
>>  C:/msys2_64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/include
>>  C:/msys2_64/mingw64/lib/gcc/../../include/c++/4.9.2
>>  C:/msys2_64/mingw64/lib/gcc/../../include/c++/4.9.2/x86_64-w64-mingw32
>>  C:/msys2_64/mingw64/lib/gcc/../../include/c++/4.9.2/backward
>>
>>
>> Built with the older MSYS2 patch ;
>> $ clang++ -E -x c++ - -v < /dev/null
>> clang version 3.7.0 (http://llvm.org/git/clang.git
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_clang.git&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=pPjfizf2zAebxGKdA0tfJNJMfhG4rOM7lwPnfPMa14Q&e=>
>> e7cee814a12b5dd16c8672543fd93efe741d5208) (http://llvm.org/git/llvm.git
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_llvm.git&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=nrLEvIb_FdlnMl1MALmnNd72UDSWQ11U46obfWTKRRA&e=>
>> d594ba081506f0f57e9801e3f81467b1766b1e04)
>> Target: x86_64-pc-windows-gnu
>> Thread model: posix
>>  "C:\\msys2_64\\mingw64\\bin\\clang++.exe" -cc1 -triple
>> x86_64-pc-windows-gnu -E -disable-free -disable-llvm-verifier
>> -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix
>> -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
>> -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info
>> -fno-unique-section-names -resource-dir
>> "C:\\msys2_64\\mingw64\\bin\\..\\lib\\clang\\3.7.0" -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../include/c++/4.9.2" -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../include/c++/4.9.2/x86_64-w64-mingw32"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../include/c++/4.9.2/backward"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../x86_64-w64-mingw32/include/c++"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../x86_64-w64-mingw32/include/c++/backward"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin\\..\\lib\\clang\\3.7.0\\include"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\bin/../x86_64-w64-mingw32/include"
>> -internal-isystem "C:\\msys2_64\\mingw64\\bin/../include"
>> -fdeprecated-macro -fdebug-compilation-dir "E:\\llvm\\buildmingw64\\bin"
>> -ferror-limit 19 -fmessage-length 0 -mstackrealign -fno-use-cxa-atexit
>> -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
>> -o - -x c++ -
>> clang -cc1 version 3.7.0 based upon LLVM 3.7.0svn default target
>> x86_64-pc-windows-gnu
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\bin/../x86_64-w64-mingw32/include/c++"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\bin/../x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\bin/../x86_64-w64-mingw32/include/c++/backward"
>> ignoring duplicate directory
>> "C:\msys2_64\mingw64\bin\..\lib\clang\3.7.0\include"
>> #include "..." search starts here:
>> #include <...> search starts here:
>>  C:\msys2_64\mingw64\bin/../include/c++/4.9.2
>>  C:\msys2_64\mingw64\bin/../include/c++/4.9.2/x86_64-w64-mingw32
>>  C:\msys2_64\mingw64\bin/../include/c++/4.9.2/backward
>>  C:\msys2_64\mingw64\bin\..\lib\clang\3.7.0\include
>>  C:\msys2_64\mingw64\bin/../x86_64-w64-mingw32/include
>>  C:\msys2_64\mingw64\bin/../include
>> End of search list.
>> New Patch
>> $ ./clang++ -E -x c++ - -v < /dev/null
>> clang version 3.7.0 (http://llvm.org/git/clang.git
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_clang.git&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=pPjfizf2zAebxGKdA0tfJNJMfhG4rOM7lwPnfPMa14Q&e=>
>> 0af047c817acbc67e61aa82f0b43a54d61b753f8) (http://llvm.org/git/llvm.git
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_llvm.git&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=r3JtGknlg70px5yvRWhv1Zl7r4WNJKqtaJd9HISLW8E&s=nrLEvIb_FdlnMl1MALmnNd72UDSWQ11U46obfWTKRRA&e=>
>> 9a9ee6f550c0789053c260203aea8430a34554fe)
>> Target: x86_64-pc-windows-gnu
>> Thread model: posix
>>  "E:\\llvm\\buildmingw64\\bin\\clang++.exe" -cc1 -triple
>> x86_64-pc-windows-gnu -E -disable-free -disable-llvm-verifier
>> -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix
>> -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables
>> -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info
>> -resource-dir "E:\\llvm\\buildmingw64\\bin\\..\\lib\\clang\\3.7.0"
>> -internal-isystem "C:\\msys2_64\\mingw64\\x86_64-w64-mingw32\\include\\c++"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32\\"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\x86_64-w64-mingw32\\include\\c++\\backward"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include\\c++"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include\\c++\\x86_64-w64-mingw32\\"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include\\c++\\backward"
>> -internal-isystem
>> "E:\\llvm\\buildmingw64\\bin\\..\\lib\\clang\\3.7.0\\include"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include"
>> -internal-isystem
>> "C:\\msys2_64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include-fixed"
>> -internal-isystem "C:\\msys2_64\\mingw64\\x86_64-w64-mingw32\\include"
>> -internal-isystem "C:\\msys2_64\\mingw64\\include" -fdeprecated-macro
>> -fdebug-compilation-dir "E:\\llvm\\buildmingw64\\bin" -ferror-limit 19
>> -fmessage-length 0 -mstackrealign -fno-use-cxa-atexit -fobjc-runtime=gcc
>> -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o - -x c++ -
>> clang -cc1 version 3.7.0 based upon LLVM 3.7.0svn default target
>> x86_64-pc-windows-gnu
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\x86_64-w64-mingw32\include\c++"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32\"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\x86_64-w64-mingw32\include\c++\backward"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\"
>> ignoring nonexistent directory
>> "C:\msys2_64\mingw64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\backward"
>> #include "..." search starts here:
>> #include <...> search starts here:
>>  E:\llvm\buildmingw64\bin\..\lib\clang\3.7.0\include
>>  C:\msys2_64\mingw64\lib\gcc\x86_64-w64-mingw32\4.9.2\include
>>  C:\msys2_64\mingw64\lib\gcc\x86_64-w64-mingw32\4.9.2\include-fixed
>>  C:\msys2_64\mingw64\x86_64-w64-mingw32\include
>>  C:\msys2_64\mingw64\include
>> End of search list.
>>
>> I assume this patch only meant to fix the official mingw-builds?
>>
>>
>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150705/c328eec1/attachment.html>
-------------- next part --------------
Index: tools/clang/lib/Driver/ToolChains.h
===================================================================
--- tools/clang/lib/Driver/ToolChains.h	(revision 241293)
+++ tools/clang/lib/Driver/ToolChains.h	(working copy)
@@ -552,6 +552,7 @@
 private:
   std::string Base;
   std::string GccLibDir;
+  std::string Ver;
   std::string Arch;
   mutable std::unique_ptr<tools::gcc::Preprocessor> Preprocessor;
   mutable std::unique_ptr<tools::gcc::Compiler> Compiler;
Index: tools/clang/lib/Driver/MinGWToolChain.cpp
===================================================================
--- tools/clang/lib/Driver/MinGWToolChain.cpp	(revision 241293)
+++ tools/clang/lib/Driver/MinGWToolChain.cpp	(working copy)
@@ -45,6 +45,7 @@
   llvm::sys::fs::directory_iterator MingW64Entry(LibDir + Arch, EC);
   if (!EC) {
     GccLibDir = MingW64Entry->path();
+    Ver = llvm::sys::path::filename(GccLibDir);
   } else {
     // If mingw-w64 not found, try looking for mingw.org.
     Arch = "mingw32";
@@ -128,16 +129,21 @@
       DriverArgs.hasArg(options::OPT_nostdincxx))
     return;
 
-  llvm::SmallString<1024> IncludeDir;
-  for (bool MingW64 : {true, false}) {
-    if (MingW64)
-      IncludeDir = Base + Arch;
-    else
-      IncludeDir = GccLibDir;
-    llvm::sys::path::append(IncludeDir, "include", "c++");
-    addSystemInclude(DriverArgs, CC1Args, IncludeDir.str());
-    IncludeDir += llvm::sys::path::get_separator();
-    addSystemInclude(DriverArgs, CC1Args, IncludeDir.str() + Arch);
-    addSystemInclude(DriverArgs, CC1Args, IncludeDir.str() + "backward");
+  // C++ includes may be found in several locations depending on distribution.
+  // mingw-w64 mingw-builds: $sysroot/i686-w64-mingw32/include/c++.
+  // mingw-w64 msys2:        $sysroot/include/c++/4.9.2
+  // mingw.org:              GccLibDir/include/c++
+  llvm::SmallVector<llvm::SmallString<1024>, 3> CppIncludeBases;
+  CppIncludeBases.emplace_back(Base);
+  llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++");
+  CppIncludeBases.emplace_back(Base);
+  llvm::sys::path::append(CppIncludeBases[1], "include", "c++", Ver);
+  CppIncludeBases.emplace_back(GccLibDir);
+  llvm::sys::path::append(CppIncludeBases[2], "include", "c++");
+  for (auto &CppIncludeBase : CppIncludeBases) {
+    CppIncludeBase += llvm::sys::path::get_separator();
+    addSystemInclude(DriverArgs, CC1Args, CppIncludeBase);
+    addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch);
+    addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward");
   }
 }


More information about the cfe-dev mailing list