使用g ++编译多线程代码(-Wl, - 不需要非工作) [英] Compiling multithread code with g++ (-Wl,--no-as-needed NOT working)

查看:130
本文介绍了使用g ++编译多线程代码(-Wl, - 不需要非工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题实际上在这里描述:使用g ++编译多线程代码
但是关于使用-Wl, - 不需要的工作的答案对我来说不起作用。

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.

-Wl, - 不需要-pthread -std = c ++ 0x 在不同的顺序也,但我还是得到:

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"

该怎么办?

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

编辑:
我尝试使用 -Wl构建, - 不需要-lpthread -std = c ++ 0x 没有运气。
代码:

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;
}

编辑:

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

推荐答案


  1. -Wl, - 不需要 -Wl, - no_as_needed ,您使用连字符

  2. -pthread 是编译器的标志,而不是链接器,链接器的正确标志是 -lpthread

  3. Mingw并不总是带有相同的线程库,使用MinGW的多线程有多个选项,您应该根据您的MinGW版本记录自己。

  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

这篇关于使用g ++编译多线程代码(-Wl, - 不需要非工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆