<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54205>54205</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang cannot find headfiles in default search path with shared library on Windows
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Rt39
</td>
</tr>
</table>
<pre>
The source code I got was from github realease 13.0.1.
I'm trying to build clang to have the default target triple to `x86_64-pc-windows-gnu` on Windows 10(21H1, 19043.1526), so I tried to compile it with my mingw-w64(TDM-GCC 10.3.0) with the following configuration:
```
cmake -S llvm -B build -G Ninja -DCMAKE_C_COMPILER:STRING=gcc -DCMAKE_CXX_COMPILER:STRING=g++ -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=C:/llvm -DLLVM_ENABLE_PROJECTS:STRING="clang" -DLLVM_DEFAULT_TARGET_TRIPLE:STRING="x86_64-pc-windows-gnu" -DLLVM_TARGETS_TO_BUILD:STRING="X86"
```
It worked pretty well. However, I found the size of the tool chain is unbearable large, up to about 6 GB. And I also found that through the help page [](https://llvm.org/docs/CMake.html#llvm-related-variables) which says that it can be built to use shared library by using MinGW with the parameter BUILD_SHARED_LIBS:BOOL, I followed through with the configuration:
```
cmake -S llvm -B build -G Ninja -DCMAKE_C_COMPILER:STRING=gcc -DCMAKE_CXX_COMPILER:STRING=g++ -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=C:/llvm_mingw_shared -DLLVM_ENABLE_PROJECTS:STRING="clang" -DLLVM_DEFAULT_TARGET_TRIPLE:STRING="x86_64-pc-windows-gnu" -DLLVM_TARGETS_TO_BUILD:STRING="X86" -DBUILD_SHARED_LIBS:BOOL="ON"
```
The compiling was smooth enough, but the compiled clang cannot pass through a simple file, like say:
```cpp
//////////// source2.cpp //////////
#include<windows.h>
int main(){}
```
and the output of clang is like:
```
PS D:\cs\c++\test> C:\llvm_mingw_shared\bin\clang source2.cpp -v
clang version 13.0.1
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir: C:\llvm_mingw_shared\bin
"C:\\llvm_mingw_shared\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name source2.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -mms-bitfields -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v "-fcoverage-compilation-dir=D:\\cs\\c++\\test" -resource-dir "C:\\llvm_mingw_shared\\lib\\clang\\13.0.1" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\backward" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0\\backward" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0\\backward" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++\\backward" -internal-isystem "C:\\llvm_mingw_shared\\lib\\clang\\13.0.1\\include" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\TDM-GCC-64\\include" -fdeprecated-macro "-fdebug-compilation-dir=D:\\cs\\c++\\test" -ferror-limit 19 -fmessage-length=105 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -exception-model=seh -fcolor-diagnostics -faddrsig -o "C:\\Users\\sunra\\AppData\\Local\\Temp\\source2-f0124a.o" -x c++ source2.cpp
clang -cc1 version 13.0.1 based upon LLVM 13.0.1 default target x86_64-pc-windows-gnu
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\backward
C:\llvm_mingw_shared\lib\clang\13.0.1\include
C:\TDM-GCC-64\x86_64-w64-mingw32\include
C:\TDM-GCC-64\include
End of search list.
source2.cpp:1:9: fatal error: cannot open file
'C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\windows.h': No such file or directory
#include<windows.h>
^
1 error generated.
```
It seems that clang only search for the first path shown on the path list. I truly have `windows.h` in ` C:\TDM-GCC-64\x86_64-w64-mingw32\include`. Also, compiling a file including `<iostream>` will be like this:
```
PS D:\cs\c++\test> C:\llvm_mingw_shared\bin\clang source2.cpp -v
clang version 13.0.1
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir: C:\llvm_mingw_shared\bin
"C:\\llvm_mingw_shared\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name source2.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -mms-bitfields -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -v "-fcoverage-compilation-dir=D:\\cs\\c++\\test" -resource-dir "C:\\llvm_mingw_shared\\lib\\clang\\13.0.1" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\backward" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include\\c++\\10.3.0\\backward" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\include\\c++\\10.3.0\\backward" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "C:\\TDM-GCC-64\\lib\\gcc\\x86_64-w64-mingw32\\10.3.0\\include\\c++\\backward" -internal-isystem "C:\\llvm_mingw_shared\\lib\\clang\\13.0.1\\include" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\TDM-GCC-64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\TDM-GCC-64\\include" -fdeprecated-macro "-fdebug-compilation-dir=D:\\cs\\c++\\test" -ferror-limit 19 -fmessage-length=105 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -exception-model=seh -fcolor-diagnostics -faddrsig -o "C:\\Users\\sunra\\AppData\\Local\\Temp\\source2-4f4eb4.o" -x c++ source2.cpp
clang -cc1 version 13.0.1 based upon LLVM 13.0.1 default target x86_64-pc-windows-gnu
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32\include\c++\10.3.0\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0\x86_64-w64-mingw32"
ignoring nonexistent directory "C:\TDM-GCC-64\include\c++\10.3.0\backward"
ignoring nonexistent directory "C:\TDM-GCC-64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\backward
C:\llvm_mingw_shared\lib\clang\13.0.1\include
C:\TDM-GCC-64\x86_64-w64-mingw32\include
C:\TDM-GCC-64\include
End of search list.
In file included from source2.cpp:1:
C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\iostream:38:10: fatal error: cannot open file 'C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\bits/c++config.h': No such file or
directory
#include <bits/c++config.h>
^
1 error generated.
```
Which, the `bits/c++config.h` is actually in `C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32\bits`.
I don't know whether there's anything to do with building shared libraries. I have tried to compile the source code switching different compilers (from gcc, TDM-GCC 10.3.0, which is based on mingw-w64 to cl, Microsoft (R) C/C++ Optimizing Compiler Version 19.30.30709 for x64) and default target triple (from x86_64-pc-windows-gnu to x86_64-pc-windows-msvc) and whether to build the shared library (which msvc cannot do so), and I finally realized that it may be the reason that I turned on the last option.
(By the way, I also tried to compile llvm with clang(getting from the realease binary), and hard as I tried, it could not pass. The linker, both ld and lld.link, complains about undefined symble when linking LLVMSupport)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztW1132jwS_jXkRsc-YAOBi1wQICm75OMk6dvuVY5sy6BWtnwsOUB__c5IMh8JpO3bJLtnl54UsDyaGc2MRuPHUiST1dnDnBElqzJmJJYJIxMyk5osqCJpKTMy43peRaRkVDCqGGm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