Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ 11 Threads, Error Pure virtual function called

here is a very minimal C++11 Thread API code that I am trying to compile

#include<iostream>
#include<thread>

using namespace std;

void threadFunction(void)
{
    cout<<"hello from thread:";//<<this_thread::get_id()<<endl;
}

int main()
{
    std::thread t(threadFunction);
    t.join();

    return 0;
}



On Compiling this as
g++ thread1.cpp -pthread -std=c++11
I get the following error
pure virtual method called
terminate called without an active exception
Aborted


What wrong, can someone please help
Note that I am compiling this on Beaglebone Black with ARM A8 processor

like image 540
Anjanu Avatar asked May 10 '14 16:05

Anjanu


2 Answers

This is a bug in either libstdc++ or Clang, depending on who you ask. It should work if you are using a version of Clang released after October 2013. What do you see when you run g++ --version?

As a workaround, you could try using this command line instead. I don't guarantee that it would work; please post a comment with your results.

g++ -pthread -std=c++11 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_{1,2,4} thread1.cpp

Here's the bug report:

http://llvm.org/bugs/show_bug.cgi?id=12730

And here's the official fix to the Clang driver:

https://llvm.org/viewvc/llvm-project?view=revision&revision=191707

I don't know if this was also previously a bug in the GCC driver, and/or whether it's been fixed.

like image 126
Quuxplusone Avatar answered Oct 19 '22 18:10

Quuxplusone


Ran into the same problem on a Raspberry Pi 2 Model B with an ARM Cortex-A7. Compiled with g++-4.7, turned out the culprit was a compiler flag:

-march=armv7-a
like image 21
Tim Avatar answered Oct 19 '22 19:10

Tim