1

I'm trying to build the pmp-library (https://github.com/pmp-library/pmp-library) under Ubuntu 20 in the Windows subsystem for Linux (WSL). More than half way through the build, I get lots of undefined references like this one:

[ 59%] Linking CXX executable ../../mconvert
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) [clone .isra.19]':
mconvert.cpp:(.text+0x86): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'

I found that it might be related to the compiler version. However, as far as I understand I am compiling all dependencies myself and I get the same error using gcc/g++-6, 7, and 9 (>https://github.com/preshing/junction/issues/37>, and Converting std::__cxx11::string to std::string)

I also found that it might be related to the command used for compiling. Using gcc the c standard lib has to linked explicitly, using g++ it is linked automatically. But did not find the information in the make files.

Any idea how to fix this error? I posted the entire output below...

[ 59%] Linking CXX executable ../../mconvert
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) [clone .isra.19]':
mconvert.cpp:(.text+0x86): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)'
/usr/bin/ld: mconvert.cpp:(.text+0xbc): undefined reference to `std::__throw_logic_error(char const*)'
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o: in function `usage_and_exit()':
mconvert.cpp:(.text+0xca): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text+0xd8): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/usr/bin/ld: mconvert.cpp:(.text+0xe6): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text+0xf0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/usr/bin/ld: mconvert.cpp:(.text+0xf7): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text+0x103): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o: in function `main':
mconvert.cpp:(.text.startup+0xff): undefined reference to `operator delete(void*)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x116): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x120): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x127): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x12f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x13e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x19d): undefined reference to `operator delete(void*)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x1b0): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x1ba): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x1c1): undefined reference to `std::cerr'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x1c9): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x1ee): undefined reference to `operator delete(void*)'
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o: in function `_GLOBAL__sub_I__Z14usage_and_exitv':
mconvert.cpp:(.text.startup+0x21c): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: mconvert.cpp:(.text.startup+0x223): undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: CMakeFiles/mconvert.dir/mconvert.cpp.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ostream& std::ostream::_M_insert<unsigned long>(unsigned long)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ctype<char>::_M_widen_init() const'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ios_base::~ios_base()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `operator new[](unsigned long)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `typeinfo for std::bad_alloc'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::_Rb_tree_increment(std::_Rb_tree_node_base*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_end_catch'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::~basic_ofstream()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_allocate_exception'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::bad_alloc::~bad_alloc()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `atan2'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ios_base::ios_base()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::cout'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::basic_ios<char, std::char_traits<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::locale::locale()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `typeinfo for float'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ostream& std::ostream::_M_insert<double>(double)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `VTT for std::basic_ofstream<char, std::char_traits<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_guard_release'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ostream::flush()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `acos'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `typeinfo for double'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `typeinfo for bool'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ostream::put(char)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_filebuf<char, std::char_traits<char> >::close()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::basic_streambuf<char, std::char_traits<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_pure_virtual'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_filebuf<char, std::char_traits<char> >::~basic_filebuf()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_throw_bad_array_new_length'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__dynamic_cast'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `sin'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__throw_bad_cast()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `operator delete[](void*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `sqrtf'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::clog'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::bad_alloc'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `tan'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_begin_catch'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_rethrow'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_throw'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char const*, unsigned long, unsigned long) const'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::locale::~locale()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::basic_ofstream<char, std::char_traits<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `cos'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `typeinfo for int'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `operator new(unsigned long)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__basic_file<char>::~__basic_file()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `sqrt'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `sincosf'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for std::basic_filebuf<char, std::char_traits<char> >'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__throw_length_error(char const*)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for __cxxabiv1::__class_type_info'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::ostream::operator<<(int)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `std::__throw_bad_alloc()'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info'
/usr/bin/ld: ../../libpmp.so.1.2.1: undefined reference to `__cxa_guard_acquire'
collect2: error: ld returned 1 exit status
make[2]: *** [src/apps/CMakeFiles/mconvert.dir/build.make:85: mconvert] Error 1
make[1]: *** [CMakeFiles/Makefile2:544: src/apps/CMakeFiles/mconvert.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
fabian
  • 103
  • 1
  • 7
  • As answer mentioned there, it's related not to compiler version but to having objects built with different values of _GLIBCXX_USE_CXX11_ABI . Is it possible that you're still using GCC 5's runtime library? CMake list of that ELF require inspection, there might be a mistake in configuration. – Swift - Friday Pie Sep 08 '20 at 08:33
  • @Swift-FridayPie, thanks for the hint. Since I am more of a casual maker, I am not sure where to look. What ELF should I check, and what am I looking for? I checked the CMake list of the pmp-library and did not find any mentions of GLIBCXX, CXX11, and ABI... – fabian Sep 09 '20 at 09:31
  • I'm not sure how to do that for your build environment, but if it tries to use libstdc++ (default for gcc <5), you have to force it to use libstdc++11 – Swift - Friday Pie Sep 09 '20 at 09:41

1 Answers1

-1

Try using g++ compiler for compiling like this

g++ <cpp file name> -o <desired file name>

To install it you may use

$ sudo apt-get install g++

Hope it works