gcc 5.1.1 requires linkage with -lpthread?

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


Jonathan Wakely writes:

> If you're using std::thread then you always needed to link to libpthread or
> you'd get an exception at run time.
>
> Now you get a failure earlier at link time, but there's no new dependency.

No, I did not get a link failure before, with gcc 4.9. I'll explain why, in  
a moment.

> No. Libstdc++ never linked to libpthread, it was always your job.

My job was this:

libcxx.so linked with libstdc++ and libpthread.

libcxx.so comes with some templates, that instantiate std::thread, etc…

a.out links with libcxx.so (and with libstdc++), and uses libcxx.so's  
templates.

This worked. libstdc++'s reference to pthread_create was resolved;  
apparently libcxx.so's linkage to libpthread was sufficient.

Now, looks like a.out ends up having an external reference to  
pthread_create(), when it didn't before, hence the link failure.

-------------- 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/b21a382d/attachment-0001.sig>


More information about the Gcc-help mailing list