获取对std :: thread :: _ M_start_thread的未定义引用 [英] Getting undefined reference to std::thread::_M_start_thread

查看:1732
本文介绍了获取对std :: thread :: _ M_start_thread的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用第三方lib(Box2D-MT)的应用程序,该应用程序是从源代码构建的。链接时,我得到这个未定义的引用错误:

$ b $ p $ b2Threading.cpp :(。text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0 _ [_ ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0 _] + 0xa4):
未定义引用'std :: thread :: _ M_start_thread(std :: shared_ptr

我用g ++编译并链接到

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

另外,我正在编译

  -std = c ++ 11 

查看libstdc ++。a我可以看到类似的符号存在(它是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>)

但是这个重载不需要第二个参数。



我搜索了所有类似的互联网,但似乎没有人(在任何情况下)都有这个问题。



任何暗示为什么我得到这个错误以及我如何解决它?

解决方案

看起来像是头文件/库版本不匹配。这是我得到的:

  $ 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);


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?

解决方案

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);

这篇关于获取对std :: thread :: _ M_start_thread的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆