<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Thu, Feb 7, 2013 at 7:47 PM, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On Feb 7, 2013, at 6:17 AM, Alexey Samsonov <<a href="mailto:samsonov@google.com">samsonov@google.com</a>> wrote:<br>

<br>
> Hi!<br>
><br>
> I'm trying to build libcxx on Linux (Ubuntu Precise) using the following command:<br>
><br>
> cmake -DLIBCXX_CXX_ABI=libsupc++ '-DLIBCXX_LIBSUPCXX_INCLUDE_PATHS=/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu/.;' -DLIBCXX_ENABLE_EXCEPTIONS=OFF -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_RTTI=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/tmp.boBpS5zFqt/libcxx_inst /tmp/tmp.boBpS5zFqt/libcxx<br>

><br>
> and I want the result to be "hermetic" in the sense that resulting static library libc++.a doesn't reference undefined symbols from std::<br>
> However, I see the following problems:<br>
><br>
> (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function std::bad_alloc::~bad_alloc(): error: undefined reference to 'std::exception::~exception()'<br>
> (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function std::bad_array_new_length::~bad_array_new_length(): error: undefined reference to 'std::exception::~exception()'<br>
> (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function std::bad_array_new_length::~bad_array_new_length(): error: undefined reference to 'std::exception::~exception()'<br>
> (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush(): error: undefined reference to 'std::uncaught_exception()'<br>

> (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function std::__1::basic_ostream<wchar_t, std::__1::char_traits<wchar_t> >::flush(): error: undefined reference to 'std::uncaught_exception()'<br>

> (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry(): error: undefined reference to 'std::uncaught_exception()'<br>

> (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry(): error: undefined reference to 'std::uncaught_exception()'<br>

> (libc++.a.memory.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/memory.cpp:function std::__1::bad_weak_ptr::~bad_weak_ptr(): error: undefined reference to 'std::exception::~exception()'<br>
> (libc++.a.memory.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/memory.cpp:function vtable for std::__1::__shared_weak_count: error: undefined reference to 'std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const'<br>

> (libc++.a.thread.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/thread.cpp:function std::__1::thread::~thread(): error: undefined reference to 'std::terminate()'<br>
><br>
> What is the correct way to for that? I have the patch (attached) that works for me, but I'm not really sure it's correct<br>
> (especially the first part).<br>
<br>
</div></div>Yeah, we tried this once:<br>
<br>
> --- include/memory    (revision 173248)<br>
> +++ include/memory    (working copy)<br>
> @@ -3629,10 +3629,9 @@<br>
>      long use_count() const _NOEXCEPT {return __shared_count::use_count();}<br>
>      __shared_weak_count* lock() _NOEXCEPT;<br>
><br>
> -    // purposefully not protected with #ifndef _LIBCPP_NO_RTTI because doing so<br>
> -    //  breaks ABI for those clients who need to compile their projects with<br>
> -    //    -fno-rtti and yet link against a libc++.dylib compiled without -fno-rtti.<br>
> +#ifndef _LIBCPP_NO_RTTI<br>
>      virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;<br>
> +#endif _LIBCPP_NO_RTTI<br>
<br>
and as the comments indicate, got bitten by it, at least on Apple platforms.<br>
<br>
Way forward:  Perhaps you could #ifdef it a little more in such a way that it isn't going to trigger except for someone trying to do exactly what you are doing:  Build a static lib on linux with rtti and exceptions off.  Or perhaps slightly more general:  Build a static lib with rtti and exceptions off.<br>
</blockquote><div><br></div><div style>Yes, I can add some #ifdefs here. But I also wonder about the second part of the patch: </div><div style>I have __GLIBCXX__ defined because of commit:</div><div style><br></div><div style>
r173164 Saleem Abdulrasool: Ensure that __GLIBCXX__ is defined when building with libsupc++.<br></div><div style><br></div><div style>and, as a result, I don't get definitions of terminate(), uncaught_exception(), exception>::~exception() and exception::what() in the resulting libc++ library,</div>
<div style>yet these functions are referenced from it.</div></div><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div></div>