Bug#763369: g++-4.9: Linker failure when using str::thread
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;
}
Reply to: