gcc 5.1.1 requires linkage with -lpthread?

Sam Varshavchik mrsam@courier-mta.com
Sat Jun 6 17:23:00 GMT 2015


Rebuilding a bunch of code from 4.9.2 to 5.1.1 resulted in a bunch of  
complaints about unresolved references to pthread_create(), and admonishing  
me for not linking with -lpthread :-)

Which was odd, since the code in question uses std::thread exclusively, and  
should only need to be linked with the default libstdc++, helpfully supplied  
by the compiler.

So, I chased this down to <thread> now making visible an explicit reference  
to pthread_create, in std::thread's constructor:

    template<typename _Callable, typename… _Args>
      explicit
      thread(_Callable&& __f, _Args&&… __args)
      {
        _M_start_thread(_M_make_routine(std::__bind_simple(
                std::forward<_Callable>(__f),
                std::forward<_Args>(__args)…)),
     reinterpret_cast<void(*)()>(&pthread_create));
      }

So that's what I'm compiling. This may be because of the ld.so configuration  
in Fedora. Even if libstdc++ is linked with -lpthread, this ends up being  
compiled as part of my code, at -O2, apparently, and I'm not linking with - 
lpthread.

Not really a complicated thing to fix up, of course. Just seems a bit odd,  
to end up requiring a linking dependency, in this manner.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20150606/9b8c9620/attachment.sig>


More information about the Gcc-help mailing list