This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -fuse-ld=gold and -pthread vs -lpthread
- From: John Steele Scott <toojays at toojays dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 29 Mar 2017 16:30:26 +1030
- Subject: Re: -fuse-ld=gold and -pthread vs -lpthread
- Authentication-results: sourceware.org; auth=none
- References: <oapu2c$fg8$1@blaine.gmane.org>
On 21/03/17 11:32, John Steele Scott wrote:
> I have a project where linking with "gcc -pthread -fuse-ld=gold ..." fails with errors about undefined pthread symbols, e.g.
>
> gcc /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.2.1/crtend.o /usr/lib/../lib64/crtn.o
> /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.2.1/libstdc++_nonshared.a(thread44.o):function std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()): error: undefined reference to 'pthread_create'
> /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.2.1/libstdc++_nonshared.a(thread44.o):function std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)()): error: undefined reference to 'pthread_create'
There were a couple of other libraries being linked in which referred to symbols in libpthread, but did not have a DT_NEEDED entry for libpthread. One of these instances was a libtool project bitten by <https://bugzilla.redhat.com/show_bug.cgi?id=661333>, the others could be fixed with simple makefile editing.
Anyhow, after fixing those problems, the above messages disappeared as well. So I've gone back to using -pthread, like I had before. All's well that ends well.
Cheers,
John