Troubles building libcxx from svn source


up vote0down votefavorite



|



The directions I followed are here: https://clang.llvm.org/get_started.html (steps 1-7, including the optional ones).



I was very careful to type everything EXACTLY as specified (so all projects are in the correct directories).



After I ran ‘cmake’, everything looked fine, no error messages.




But when I try to build with ‘make’, when it gets to libcxx it has linker errors:



. . . [100%] Built target cxx_objects [100%] Linking CXX shared library ../../../lib/libc++.so CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::(anonymous namespace)::__throw_runtime_error(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&)‘: locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0xf): undefined reference to __cxa_allocate_exception' locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0x33): undefined reference to __cxa_throw’ locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0x3e): undefined reference to __cxa_free_exception' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::ctype_byname<wchar_t>::do_widen(char) const’: locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE8do_widenEc+0x43): undefined reference to __cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::ctype_byname<wchar_t>::do_widen(char const*, char const*, wchar_t*) const’: locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE8do_widenEPKcS3_Pw+0x7a): undefined reference to __cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::ctype_byname<wchar_t>::do_narrow(wchar_t, char) const’: locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE9do_narrowEwc+0x46): undefined reference to __cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::ctype_byname<wchar_t>::do_narrow(wchar_t const*, wchar_t const*, char, char*) const’: locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE9do_narrowEPKwS3_cPc+0x8d): undefined reference to __cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function std::__1::locale::__imp::use_facet(long) const [clone .part.18]‘: locale.cpp:(.text.unlikely._ZNKSt3__16locale5__imp9use_facetEl.part.18+0x7): undefined reference to __cxa_allocate_exception' locale.cpp:(.text.unlikely._ZNKSt3__16locale5__imp9use_facetEl.part.18+0x28): undefined reference to cxa_throw’ CMakeFiles/cxx_objects.dir//src/locale.cpp.o: In function std::__1::__time_get_c_storage<char>::__weeks() const': locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x21): undefined reference to __cxa_guard_acquire’ locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x167): undefined reference to __cxa_guard_release' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x178): undefined reference to __cxa_guard_acquire’ locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x35a): undefined reference to __cxa_guard_release' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x383): undefined reference to __cxa_guard_abort’ . . .`



Fresh Ubuntu 17.04 install (X86) with the preinstalled gcc being used to build.



(neither clang nor libc++ are present in the default 17.04 release).



|

up vote0down votefavorite <c++ - Linker errors building libcxx on fresh Ubuntu install - Stack Overflow;
<c++ - Linker errors building libcxx on fresh Ubuntu install - Stack Overflow;
  
The directions I followed are here: Clang - Getting Started (steps 1-7, including the optional ones).

I was very careful to type everything EXACTLY as specified (so all projects are in the correct directories).

After I ran 'cmake', everything looked fine, no error messages.

But when I try to build with 'make', when it gets to libcxx it has linker errors:

>. . . [100%] Built target cxx_objects [100%] Linking CXX shared library ../../../lib/libc++.so CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::(anonymous namespace)::__throw_runtime_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)': locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0xf): undefined reference to `__cxa_allocate_exception' locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0x33): undefined reference to `__cxa_throw' locale.cpp:(.text.unlikely._ZNSt3__112_GLOBAL__N_1L21__throw_runtime_errorERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE+0x3e): undefined reference to `__cxa_free_exception' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::ctype_byname<wchar_t>::do_widen(char) const': locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE8do_widenEc+0x43): undefined reference to `__cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::ctype_byname<wchar_t>::do_widen(char const*, char const*, wchar_t*) const': locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE8do_widenEPKcS3_Pw+0x7a): undefined reference to `__cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::ctype_byname<wchar_t>::do_narrow(wchar_t, char) const': locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE9do_narrowEwc+0x46): undefined reference to `__cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::ctype_byname<wchar_t>::do_narrow(wchar_t const*, wchar_t const*, char, char*) const': locale.cpp:(.text._ZNKSt3__112ctype_bynameIwE9do_narrowEPKwS3_cPc+0x8d): undefined reference to `__cxa_call_unexpected' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::locale::__imp::use_facet(long) const [clone .part.18]': locale.cpp:(.text.unlikely._ZNKSt3__16locale5__imp9use_facetEl.part.18+0x7): undefined reference to `__cxa_allocate_exception' locale.cpp:(.text.unlikely._ZNKSt3__16locale5__imp9use_facetEl.part.18+0x28): undefined reference to `__cxa_throw' CMakeFiles/cxx_objects.dir/__/src/locale.cpp.o: In function `std::__1::__time_get_c_storage<char>::__weeks() const': locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x21): undefined reference to `__cxa_guard_acquire' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x167): undefined reference to `__cxa_guard_release' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x178): undefined reference to `__cxa_guard_acquire' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x35a): undefined reference to `__cxa_guard_release' locale.cpp:(.text._ZNKSt3__120__time_get_c_storageIcE7__weeksEv+0x383): undefined reference to `__cxa_guard_abort' . . . |'

These missing symbols are things from the c++ abi library, i.e. either libcxxabi, libcxxrt, or libsupc++, depending on your platform.

Jon

After digging through makefiles, the issue is that on a new Linux install there is only libstdc++, and the CMakeLists file was sticking -nodefaultlibs in the link instructions.

So no c++ abi was present as you pointed out Jon (and that you for taking the time to respond, I appreciate it!)

Adding -DLIBCXX_CXX_ABI=libstdc++ to the top-level cmake invocation seems to have fixed the problem; I’m building now so we’ll see.

The Clang documentation is a bit out-of-date, and should probably include libc++abi by default as well. That way the build just works.