【问题标题】:Issue with std::thread from c++11来自 c++11 的 std::thread 问题
【发布时间】:2017-02-04 22:54:54
【问题描述】:

我在尝试从标准模板库编译具有多线程的程序时遇到了一些麻烦。 当我尝试编译以下程序时,它返回给我一个模糊的错误:

#include <iostream>
#include <thread>

void foo()
{
    std::cout << "Thread 1\n";
}

int main(int argc, char** argv)
{
    std::thread tr(foo);
    std::cout << "Main thread\n";
    tr.join();

    return 0;
}

我不明白错误:

/tmp/ccE8EtL1.o : In the function « std::thread::thread<void (&)()>(void (&)()) » :
 file.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x21) : undefined reference to « pthread_create »
  collect2: error : ld has return 1 execution status code

我用 :

编译它

g++ -std=c++14 file.cpp -o test -Wall

谁能帮帮我?

【问题讨论】:

    标签: c++ multithreading g++ std stdthread


    【解决方案1】:
    猜你喜欢
    • 2013-11-26
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多