user3452622
user3452622

Reputation: 41

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.

Upvotes: 4

Views: 6933

Answers (2)

Vinod Patidar
Vinod Patidar

Reputation: 362

g++  filename.c -std=c++11 -lpthread

i am compiling your code with above command its working perfect.

Upvotes: 1

user2485710
user2485710

Reputation: 9811

  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

Upvotes: 4

Related Questions