其他分享
首页 > 其他分享> > c – 获取对std :: thread :: _ M_start_thread的未定义引用

c – 获取对std :: thread :: _ M_start_thread的未定义引用

作者:互联网

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

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 (*)())'

我正在建设与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);

标签:c,multithreading,g,undefined-reference,ld
来源: https://codeday.me/bug/20191008/1871636.html