--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: g++-4.9: Linker failure when using str::thread
- From: Ralf Jung <post@ralfj.de>
- Date: Mon, 29 Sep 2014 20:28:33 +0200
- Message-id: <20140929182833.2559.10735.reportbug@r-schnelltop>
Package: g++-4.9
Version: 4.9.1-15
Severity: normal
Dear Maintainer,
when compiling a C++11 program that uses std::thread, I get the following
linker failure:
$ g++ -std=c++11 threadtest.cpp -o threadtest
/tmp/cc2mc1l4.o: In function `std::thread::thread<void (*)()>(void (*&&)())':
threadtest.cpp:(.text._ZNSt6threadC2IPFvvEIEEEOT_DpOT0_[_ZNSt6threadC5IPFvvEIEEEOT_DpOT0_]+0x1e): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
The program used to compile and run just fine around a month ago.
The problem also affects clang++. I will attach a small example program.
The program compiles and runs fine when I add "-pthread" to the flags
(this work-around applies to both g++ and clang++). However, it was
my understanding (and expectation) that this flag is no longer needed
with C++11 - in fact, I shouldn't even know that it's pthreads
implementing the std::thread class.
Kind regards
Ralf
-- System Information:
Debian Release: jessie/sid
APT prefers testing
APT policy: (990, 'testing'), (100, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.15.10 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages g++-4.9 depends on:
ii gcc-4.9 4.9.1-15
ii gcc-4.9-base 4.9.1-15
ii libc6 2.19-11
ii libcloog-isl4 0.18.2-1
ii libgmp10 2:6.0.0+dfsg-6
ii libisl10 0.12.2-2
ii libmpc3 1.0.2-1
ii libmpfr4 3.1.2-1
ii libstdc++-4.9-dev 4.9.1-15
ii zlib1g 1:1.2.8.dfsg-2
g++-4.9 recommends no packages.
Versions of packages g++-4.9 suggests:
pn g++-4.9-multilib <none>
ii gcc-4.9-doc 4.9.1-2
pn libstdc++6-4.9-dbg <none>
-- no debconf information
#include <thread>
#include <iostream>
void thread_fun(void)
{
std::cout << "In Thread" << std::endl;
}
int main(void)
{
std::thread(&thread_fun).join();
return 0;
}
--- End Message ---
--- Begin Message ---
- To: Ralf Jung <post@ralfj.de>, 763369-done@bugs.debian.org
- Subject: Re: Bug#763369: g++-4.9: Linker failure when using str::thread
- From: Matthias Klose <doko@debian.org>
- Date: Wed, 05 Nov 2014 14:53:07 +0100
- Message-id: <545A2BC3.6040908@debian.org>
- In-reply-to: <20140929182833.2559.10735.reportbug@r-schnelltop>
- References: <20140929182833.2559.10735.reportbug@r-schnelltop>
Am 29.09.2014 um 20:28 schrieb Ralf Jung:
> Package: g++-4.9
> Version: 4.9.1-15
> Severity: normal
>
> Dear Maintainer,
>
> when compiling a C++11 program that uses std::thread, I get the following
> linker failure:
>
> $ g++ -std=c++11 threadtest.cpp -o threadtest
> /tmp/cc2mc1l4.o: In function `std::thread::thread<void (*)()>(void (*&&)())':
> threadtest.cpp:(.text._ZNSt6threadC2IPFvvEIEEEOT_DpOT0_[_ZNSt6threadC5IPFvvEIEEEOT_DpOT0_]+0x1e): undefined reference to `pthread_create'
> collect2: error: ld returned 1 exit status
>
> The program used to compile and run just fine around a month ago.
> The problem also affects clang++. I will attach a small example program.
>
> The program compiles and runs fine when I add "-pthread" to the flags
> (this work-around applies to both g++ and clang++). However, it was
> my understanding (and expectation) that this flag is no longer needed
> with C++11 - in fact, I shouldn't even know that it's pthreads
> implementing the std::thread class.
this is expected behaviour now. You have to link with -pthread.
--- End Message ---