clang/lld 7 を使用して Ubuntu 18.04 から、clang/lld 10 および boost 1.71 を使用して 1.65 を 20.04 にアップグレードした後、対処方法がわからないリンカー エラーが発生しました。互換性のないペアであることが知られている Ubuntu 20.04 の clang & boost はありますか? clang を使用して Ubuntu 20.04 でコンパイルするためのオプションは何ですか?
エラーの最小限の例は
#include <boost/thread/shared_mutex.hpp>
int main() {
boost::shared_mutex sm;
}
ノート:
- GCC 9 とゴールド リンカーで問題なく動作します。
- clang + gold リンカーの組み合わせはほとんど同じエラー メッセージで失敗し、bfd リンカーは非常に短いエラー メッセージで失敗します。以下の出力も示します。
- 同じエラーは、clang/lld 10 ではなく 9 で発生します。
ubuntu 20.04 システムまたはコンテナーで簡単に再現できる最小限の例を作成しました。複製には、ubuntu:focal
dockerhub のプレーン コンテナーを使用しました。
- clang/lld 10 をインストールし、1.71 をブーストします
apt update && apt install clang lld libboost-thread-dev
update-alternatives --install "/usr/bin/ld" "ld" "/usr/bin/ld.lld-10" 30
これですべての要件がインストールされ、LLD がデフォルトのリンカーになります。
- 最小限の例を作成し、コンパイル/リンクします
root@d66452260792:/# cat x.cpp
#include <boost/thread/shared_mutex.hpp>
int main() {
boost::shared_mutex sm;
}
root@d66452260792:/# clang -lboost_thread x.cpp
- 期待される結果:
successful compilation
- 実結果
- BFD リンカ (GNU ld 2.34) を使用:
/usr/bin/ld: /tmp/x-a145e4.o: undefined reference to symbol '_ZTVN10__cxxabiv121__vmi_class_type_infoE@@CXXABI_1.3'
/usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
- リンカとして LLD 10 を使用 (ただし、ゴールド リンカ エラーは非常によく似ています):
ld: error: undefined symbol: std::allocator<char>::allocator()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::generic_error_category_message[abi:cxx11](int))
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::generic_error_category_message[abi:cxx11](int))
ld: error: undefined symbol: std::allocator<char>::~allocator()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::generic_error_category_message[abi:cxx11](int))
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::generic_error_category_message[abi:cxx11](int))
ld: error: undefined symbol: std::_V2::generic_category()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(int, std::error_condition const&) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(std::error_code const&, int) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(std::error_code const&, int) const)
ld: error: undefined symbol: typeinfo for std::_V2::error_category
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(int, std::error_condition const&) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(std::error_code const&, int) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(typeinfo for boost::system::detail::std_category)
ld: error: undefined symbol: __dynamic_cast
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(int, std::error_condition const&) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::equivalent(std::error_code const&, int) const)
ld: error: undefined symbol: __cxa_begin_catch
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(__clang_call_terminate)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::error_category::message(int, char*, unsigned long) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(void std::_Rb_tree<boost::system::error_category const*, std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > >, std::_Select1st<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >, boost::system::detail::cat_ptr_less, std::allocator<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > > >::_M_construct_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >(std::_Rb_tree_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >*, std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > >&&))
ld: error: undefined symbol: std::terminate()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(__clang_call_terminate)
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::empty() const
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
ld: error: undefined symbol: std::runtime_error::what() const
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char const*)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::error_category::message(int, char*, unsigned long) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::~system_error())
ld: error: undefined symbol: __cxa_end_catch
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::error_category::message(int, char*, unsigned long) const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(void std::_Rb_tree<boost::system::error_category const*, std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > >, std::_Select1st<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >, boost::system::detail::cat_ptr_less, std::allocator<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > > >::_M_construct_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >(std::_Rb_tree_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >*, std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > >&&))
ld: error: undefined symbol: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::what() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::error_category::message(int, char*, unsigned long) const)
ld: error: undefined symbol: std::_V2::error_category::~error_category()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::~std_category())
ld: error: undefined symbol: operator delete(void*)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::std_category::~std_category())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::~system_error())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::to_std_category(boost::system::error_category const&))
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > > >::deallocate(std::_Rb_tree_node<std::pair<boost::system::error_category const* const, std::unique_ptr<boost::system::detail::std_category, std::default_delete<boost::system::detail::std_category> > > >*, unsigned long))
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::exception_detail::error_info_injector<boost::thread_resource_error>::~error_info_injector())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::thread_resource_error::~thread_resource_error())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::thread_exception::~thread_exception())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >::~clone_impl())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >::clone() const)
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::wrapexcept<boost::thread_resource_error>::~wrapexcept())
ld: error: undefined symbol: std::runtime_error::~runtime_error()
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::~system_error())
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::system_error::system_error(boost::system::system_error const&))
ld: error: undefined symbol: __cxa_guard_acquire
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::to_std_category(boost::system::error_category const&))
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::to_std_category(boost::system::error_category const&))
>>> referenced by x.cpp
>>> /tmp/x-dd4c59.o:(boost::system::detail::to_std_category(boost::system::error_category const&))
ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)