Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling multithread code with g++ (-Wl,--no-as-needed NOT working)

My problem is actually described here: Compiling multithread code with g++. But the answer regarding the work around by using "-Wl,--no-as-needed" is not working for me.

I've added -Wl,--no-as-needed -pthread -std=c++0x in different orders also, but I still get the:

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

What to do?

Info: 
Ubuntu 12.04LTS
Running Eclipse CDT
g++ v4.8.1 

Edit: I tried building with -Wl,--no-as-needed -lpthread -std=c++0x with no luck. The code:

#include <iostream>
#include <chrono>
#include <thread>

void foo()
{
    std::cout << "Thread 1 created.." << std::endl;
}

int main()
{
    std::thread t1(foo);

    t1.join();

    return 0;
}

Edit: So unfortunately none of your suggestions worked. I decided to use Boost instead.

like image 702
user3452622 Avatar asked Sep 17 '25 23:09

user3452622


1 Answers

  1. it's -Wl,--no-as-needed not -Wl,--no_as_needed, you use the hyphen
  2. -pthread is a flag for the compiler, not the linker, the right one for the linker is -lpthread
  3. Mingw doesn't always comes with the same threading library, there are more than 1 options for multithreading with MinGW, you should document yourself about this according to your MinGW build
like image 192
user2485710 Avatar answered Sep 20 '25 14:09

user2485710