0

我的主机操作系统是:

Fedora 22 x64

gcc-g++ 版本是:

5.1.1

日食 cdt 版本:

Eclipse CDT Mars Release V4.5.0

这是我的简单演示代码列表:

#include <thread>
void func(){}

int main(int argc, char** argv)
{
    std::thread ts(func);
    ts.join();
    return 0;
}

这是我的 cdt 配置(错误配置):

Project Properties->C/C++Build->Tool Chain Editor->(use Linux GCC as current)
Project Properties->C/C++Build->Settings->GCC C++ Compiler->Dialet->(ISO C++11)
Project Properties->C/C++Build->Settings->GCC C Compiler->Dialet->(ISO C11)
Project Properties->C/C++Build->Settings->GCC C++ Linker->(add pthread)

Project Properties->C/C++General->Paths and Symbols->Symbols
->add '__GXX_EXPERIMENTAL_CXX0X__' to GNU C++

Project Properties->C/C++General->PreprocessorIncludePaths,Macros etc.->Providers
->(Select only 'CDT GCC Built-in Compiler Settings' and add'-std=c++11' to command)

结果是:

the project can build and run successfully
but eclipse CDT always show error: Symbol 'thread' could not be resolved
4

1 回答 1

0

可以被std::thread ts(func);认为是函数定义。改为使用std::thread ts{func};。线程也需要-pthread为编译器/链接器设置 - 比如:g++ -std=c++11 -pthread prog.cpp.

于 2015-09-02T06:27:15.440 回答