6

This is not a duplicate question, because the solutions presented are not working on my compiler. I am trying to compile and run the following example from this question.

#include <thread>
#include <iostream>

int main(int, char **){
    std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
    tt.join();
}

I have attempted to use the solutions presented in both that original question as well as the accepted answer to this duplicate. However, although I tried all the combinations listed, and in particular tried

g++  main.cpp -o main.out -pthread -std=c++11

When I run the resulting executable, I still get

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)

Here is the output of g++ --version.

g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Is there a different ordering or set of commands I need to use for g++ 4.8.1?

5
  • 2
    4.8.1 has a bug. bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1228201 Commented Jan 15, 2014 at 5:44
  • I see. Unfortunately the proposed workaround also doesn't work. I hope someone on SO knows a better workaround. Commented Jan 15, 2014 at 5:50
  • Double check that you aren't running a previously built version of your application. Commented Jan 15, 2014 at 5:52
  • I manually remove the executable before I rebuild just to be sure. Commented Jan 15, 2014 at 5:54
  • 2
    Use Clang. I don't use Gcc for c++11 & 14 related stuff. Because clang is just simply faster than Gcc to implement these new features. And compiling Clang now is just like a piece of case. Commented Jan 15, 2014 at 6:06

1 Answer 1

10

this was answered here

g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.