<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84490>84490</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Static libc++ on Windows has problems with missing exception related symbols.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tru
</td>
</tr>
</table>
<pre>
On Windows if you build libc++ as a static .lib you will get this error on a simple helloworld program:
I build the program like this:
```
clang-cl.exe /Fohello.obj /c hello.cpp /clang:-nostdinc++ \
/clang:-cxx-isystembuild/include/c++/v1 \
/clang:-cxx-isystembuild/include/x86_64-pc-windows-msvc/c++/v1 \
/D_CRT_STDIO_ISO_WIDE_SPECIFIERS /EHsc
lld-link.exe /out:hello.exe /debug hello.obj /libpath:build/lib/x86_64-pc-windows-msvc
```
<details>
<summary>Error output from lld-link</summary>
```
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrCreate(void *)
>>> referenced by libc++.lib(exception.cpp.obj):(public: __cdecl std::exception_ptr::exception_ptr(void))
>>> referenced by libc++.lib(exception.cpp.obj):(public: __cdecl std::exception_ptr::exception_ptr(std::nullptr_t))
>>> referenced by libc++.lib(exception.cpp.obj):(public: class std::exception_ptr & __cdecl std::exception_ptr::operator=(std::nullptr_t))
>>> referenced 4 more times
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrCopy(void *, void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(public: __cdecl std::exception_ptr::exception_ptr(class std::exception_ptr const &))
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrAssign(void *, void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(public: class std::exception_ptr & __cdecl std::exception_ptr::operator=(class std::exception_ptr const &))
>>> referenced by libc++.lib(exception.cpp.obj):(public: class std::exception_ptr & __cdecl std::exception_ptr::operator=(std::nullptr_t))
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrDestroy(void *)
>>> referenced by libc++.lib(exception.cpp.obj):(public: class std::exception_ptr & __cdecl std::exception_ptr::operator=(std::nullptr_t))
>>> referenced by libc++.lib(exception.cpp.obj):(public: __cdecl std::exception_ptr::~exception_ptr(void))
>>> referenced by libc++.lib(exception.cpp.obj):(int `class __copy_exception_ptr::exception_ptr __cdecl std::__copy_exception_ptr(void *, void const *)'::`1'::dtor$4)
>>> referenced 4 more times
lld-link: error: undefined symbol: bool __cdecl __ExceptionPtrToBool(void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(public: bool __cdecl std::exception_ptr::operator bool(void) const)
lld-link: error: undefined symbol: bool __cdecl __ExceptionPtrCompare(void const *, void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(bool __cdecl std::operator==(class std::exception_ptr const &, class std::exception_ptr const &))
>>> referenced by libc++.lib(exception.cpp.obj):(public: void __cdecl std::nested_exception::rethrow_nested(void) const)
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrSwap(void *, void *)
>>> referenced by libc++.lib(exception.cpp.obj):(void __cdecl std::swap(class std::exception_ptr &, class std::exception_ptr &))
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrCopyException(void *, void const *, void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(class std::exception_ptr __cdecl std::__copy_exception_ptr(void *, void const *))
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrCurrentException(void *)
>>> referenced by libc++.lib(exception.cpp.obj):(class std::exception_ptr __cdecl std::current_exception(void))
>>> referenced by libc++.lib(exception.cpp.obj):(public: __cdecl std::nested_exception::nested_exception(void))
lld-link: error: undefined symbol: void __cdecl __ExceptionPtrRethrow(void const *)
>>> referenced by libc++.lib(exception.cpp.obj):(void __cdecl std::rethrow_exception(class std::exception_ptr))
```
</details>
This is something we discussed at EuroLLVM a year ago @zmodem @petrhosek @mstorsjo - but I couldn't find a issue for it so I wanted to track it to get a final fix in for this.
I was able to do some stubs for this in my own application:
```
void __cdecl __ExceptionPtrCreate(void *) { }
void __cdecl __ExceptionPtrCopy(void *, void const *) { }
void __cdecl __ExceptionPtrDestroy(void *) { }
bool __cdecl __ExceptionPtrToBool(void const *) { return false; }
bool __cdecl __ExceptionPtrCompare(void const *, void const *) { return false; }
void __cdecl __ExceptionPtrSwap(void *, void *) { }
void __cdecl __ExceptionPtrCopyException(void *, void const *, void const *) { }
void __cdecl __ExceptionPtrCurrentException(void *) { }
void __cdecl __ExceptionPtrRethrow(void const *) { }
void __cdecl __ExceptionPtrAssign(void *, void const *) { }
```
Which made the program compile and run (without using exceptions of course).
But the question is how do we solve this long term. I think @petrhosek was talking about getting the source from Microsoft in order to put it into libc++, but that it had stalled and we couldn't get to a good conclusion.
Any input on this would help since we are making a push to see if we can replace MSVC STL with libc++ in some of our applications.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWV9v4roS_zTmZQRKE9rCAw-UP7pIu9qjbXX2ETn2hHjreHL9p5T7cD_7lZPSwlmWsr1wzkoVxWZmPPPzzM_JmDunVgZxxK7v2PW0w4MvyY68DZ2c5Gb0xcA3ZSStHagCNhQgD0pL0CoXLL1j6R1wBxyc514J6GmVN1JrpTWs0IMvlQO0liyQiYKqqjVCiVrTmqyWUFtaWV6xbMySKUtePhcvC_kStxKg1SM2Bv8iy26Sl79mKDQ3q67QPXxGYOl8Ts1qPcq_x6FoF--Jum6GUZpl464h56Uy27DY9aQ1B3tS4vm5q9zGeawaB1k6V0boIDFKtbosnT9d7Rg4Wf95cLO86Xdr0V23oHcr9ySOGp4uJ18flvcP08WX5eL-y_LbYjpb3v8xmyzmi9nX-ygy-5cTrYLWsquVedwiQ8GzbNzC8TIlMQ8r2ANMq7zmvmTZeOuxVvnPvT20JS-f2USi50o7ls1ep1yoKm43LJvN2jQJvg4eCksVbB1m2YSl8zfJI7v_pjJu8y5-CUZioQxKcJsqJx3nnkhJWC6FRKFhuZw9C6y9IvOHtxOL3CNLB40MS8csHW79nbV_YLFAi0aghHyzUw-9BpwBbs3FPItIRhPZm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