Getting undefined reference to std::thread::_M_start_thread

Bogdan Ionitza picture Bogdan Ionitza · Jul 6, 2016 · Viewed 7.7k times · Source

I'm building an app that uses a 3rd party lib (Box2D-MT) which I build from sources. When linking, I get this undefined reference error:

b2Threading.cpp:(.text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_[_ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_]+0xa4): 
undefined reference to 'std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())'

I am building with g++ and link with

-lBox2D -lpthread -lrt -ldl -lstdc++

also, I am compiling with

-std=c++11

looking into libstdc++.a I can see a similar this symbol exists (it's "T"):

nm -C /usr/lib/gcc/x86_64-linux-gnu/4.9.2/libstdc++.a | grep _M_start_thread
0000000000000000 T std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)

but this overload doesn't take a second parameter.

I've searched all the internet for something similar, but no one seems to have had this issue before (in any context).

Any hint on why I get this error and how I could solve it?

Answer

n. &#39;pronouns&#39; m. picture n. 'pronouns' m. · Jul 6, 2016

Looks like a headers/libraries version mismatch. This is what I've got:

$ nm -C /pkgs/gcc/4.9.2/lib/libstdc++.a | grep std::thread::_M_start_thread
00000000 T std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)

$ nm -C /pkgs/gcc/5.2.0/lib/libstdc++.a | grep std::thread::_M_start_thread
00000000 T std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)
00000000 T std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())

$ fgrep -r M_start_thread /usr/intel/pkgs/gcc/4.9.2/include/
/pkgs/gcc/4.9.2/include/c++/4.9.2/thread:        _M_start_thread(_M_make_routine(std::__bind_simple(
/pkgs/gcc/4.9.2/include/c++/4.9.2/thread:    _M_start_thread(__shared_base_type);

$ fgrep -r M_start_thread /usr/intel/pkgs/gcc/5.2.0/include/
/pkgs/gcc/5.2.0/include/c++/5.2.0/thread:        _M_start_thread(_M_make_routine(std::__bind_simple(
/pkgs/gcc/5.2.0/include/c++/5.2.0/thread:        _M_start_thread(_M_make_routine(std::__bind_simple(
/pkgs/gcc/5.2.0/include/c++/5.2.0/thread:    _M_start_thread(__shared_base_type, void (*)());
/pkgs/gcc/5.2.0/include/c++/5.2.0/thread:    _M_start_thread(__shared_base_type);