<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56357>56357</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-14 + PCH + libstdc++: missing symbols, libc++ ok
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jcelerier
</td>
</tr>
</table>
<pre>
Hello,
repro:
std.hpp:
```c++
#pragma once
#include <vector>
#include <string>
#include <variant>
#include <optional>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
```
main.cpp:
```c++
#include "std.hpp"
int main() {
printf("hello world");
}
```
env:
```
$ export CXXFLAGS="-std=c++20 -fvisibility=hidden -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Bsymbolic -fno-semantic-interposition -O0 -g0"
```
build PCHs:
```
# with libc++ (14)
$ clang++ $(echo $CXXFLAGS) -stdlib=libc++ std.hpp -x c++-header -fpch-instantiate-templates -fpch-codegen -fpch-debuginfo -o clang-stdlib.pch
$ clang++ $(echo $CXXFLAGS) -c clang-stdlib.pch -o clang-stdlib.o
# with libstdc++ (12)
$ clang++ $(echo $CXXFLAGS) std.hpp -x c++-header -fpch-instantiate-templates -fpch-codegen -fpch-debuginfo -o gcc-stdlib.pch
$ clang++ $(echo $CXXFLAGS) -c gcc-stdlib.pch -o gcc-stdlib.o
```
use PCHs:
```
# with libc++
# build
$ clang++ -stdlib=libc++ $(echo $CXXFLAGS) -include-pch clang-stdlib.pch -c main.cpp -o clang-main.o
# link
$ clang++ -stdlib=libc++ $(echo $CXXFLAGS) -fuse-ld=lld clang-stdlib.o clang-main.o
$ ./a.out # ok !
```
```
# with libstdc++
# build
$ clang++ $(echo $CXXFLAGS) -include-pch gcc-stdlib.pch -c main.cpp -o gcc-main.o
# link
$ clang++ $(echo $CXXFLAGS) -fuse-ld=lld gcc-stdlib.o gcc-main.o
ld.lld: error: undefined symbol: void std::__cxx11::basic_string<char8_t, std::char_traits<char8_t>, std::allocator<char8_t> >::_M_construct<char8_t const*>(char8_t const*, char8_t const*, std::forward_iterator_tag)
>>> referenced by gcc-stdlib.pch
>>> gcc-stdlib.o:(std::__cxx11::basic_string<char8_t, std::char_traits<char8_t>, std::allocator<char8_t> >::basic_string(char8_t const*, unsigned long, std::allocator<char8_t> const&))
ld.lld: error: undefined symbol: void std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >::_M_construct<char16_t const*>(char16_t const*, char16_t const*, std::forward_iterator_tag)
>>> referenced by gcc-stdlib.pch
>>> gcc-stdlib.o:(std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> >::basic_string(char16_t const*, unsigned long, std::allocator<char16_t> const&))
ld.lld: error: undefined symbol: void std::__cxx11::basic_string<char32_t, std::char_traits<char32_t>, std::allocator<char32_t> >::_M_construct<char32_t const*>(char32_t const*, char32_t const*, std::forward_iterator_tag)
>>> referenced by gcc-stdlib.pch
>>> gcc-stdlib.o:(std::__cxx11::basic_string<char32_t, std::char_traits<char32_t>, std::allocator<char32_t> >::basic_string(char32_t const*, unsigned long, std::allocator<char32_t> const&))
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV0uTozYQ_jX4osKFhZ8HDh5PJntIKqnKZW8uIQnQjowoSXg8_z4tHjYM-LGbTFI7RRnobvrx9TdSK1bsPfrCpVQe3nnBsxds61_NC628cNuVGcumWVFcpMugvqiHn9xVS3FYaJIeCFI55WeZyKksGUdeuDtyapX2wl_GlMZqkadXlEeiBcntFa0qrFA5kVfURKZKC5sdrujpgdjsmg5qF-qKUihImpOO3xaYLnoHIvIpfQS-s2uMW8gxrrUit8g58vDawxvkrZqvECoANptUcpy5hqI3pSVzX-KNF7beV883UuT5cZhdm9Yc8VOhtEW7r19fftv--pcXPoN3H1KEp6YGHCA_OQojYiGFf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