如何用GCC5.1 cinfig CDT(mars)来解析“std :: thread”符号?

时间:2015-09-02 03:04:36

标签: c++ eclipse gcc eclipse-cdt eclipse-mars

我的主机操作系统是:

Fedora 22 x64

gcc-g ++版本是:

5.1.1

eclipse cdt version:

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 config(配置错误):

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

1 个答案:

答案 0 :(得分:0)

std::thread ts(func);可能被视为功能定义。请改用std::thread ts{func};。线程还需要-pthread设置编译器/链接器 - 例如:g++ -std=c++11 -pthread prog.cpp