<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152763>152763</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
undefined symbol: std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int) when using libcxx with newlib
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
inglorion
</td>
</tr>
</table>
<pre>
On #131921, it was [noted](https://github.com/llvm/llvm-project/pull/131921#issuecomment-2737539434) that the change caused an undefined symbol in some situations. What happens is that `libcxx_static.a` ends up containing a definition of `std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long long, std::__1::ios_base::seekdir, unsigned int)` and a reference to `std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int)`. The difference is the type of the first parameter: `long long` vs. `long`.
At link time, this will result in an error such as
```
error: undefined symbol: std::__1::basic_streambuf<char, std::__1::char_traits<char>>::seekoff(long, std::__1::ios_base::seekdir, unsigned int)
```
with references from `vtable for std::__1::__stdinbuf<char>` and similar.
The difference is caused by these lines in `libcxx/include/__fwd/ios.h`:
```
#if defined(_NEWLIB_VERSION)
// On newlib, off_t is 'long int'
using streamoff = long int; // for char_traits in <string>
#elseusing streamoff = long long; // for char_traits in <string>
#endif
```
On systems with newlib, it is possible to get to this code with or without `_NEWLIB_VERSION` being defined. The inclusion of newlib header files causes `_NEWLIB_VERSION` to be defined, so including libc headers before libcxx headers will cause `_NEWLIB_VERSION` to be defined, resulting in streamoff being `long int`. However, if libcxx headers are included without first including newlib headers, `_NEWLIB_VERSION` will be undefined and streamoff will be `long long`. The inconsistency results in the link error.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUVt2K4zgTfRrlppjgSImTXOQi_RO-gY9p2F12Lo1slePakaWgkjv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