gcc 4.5.1配置C ++ 0x线程支持的选项

时间:2010-08-24 04:46:25

标签: c++ gcc cygwin

我正在尝试为cygwin编译gcc 4.5.1并支持C ++ 0x线程。 但是,生成的gcc无法识别-pthread选项。

我的配置命令是:

./configure --enable-bootstrap --enable-shared --enable-shared-libgcc
            --with-gnu-ld --enable-languages=c,c++ --enable-libgomp
            --enable-libssp --enable-threads=posix --with-__thread

示例程序是:

#include <iostream>
#include <thread>
using namespace std;

void hello()
{
 cout << "Hello Concurrent World!" << endl;
}

int main()
{
 cout << "starting" << endl;
 thread t(hello);
 t.join();
 cout << "ending" << endl;
 return 0;
}

我正在使用

编译C ++程序
$ gcc -Wall -g -std=c++0x -pthread Trial.cpp
gcc: unrecognized option '-pthread'
Trial.cpp: In function `int main()':
Trial.cpp:21:5: error: `thread' was not declared in this scope
Trial.cpp:21:12: error: expected `;' before `t'
Trial.cpp:22:5: error: `t' was not declared in this scope

我的问题是我该如何配置gcc?

2 个答案:

答案 0 :(得分:0)

我能够使用g++仅使用-pthread-std=c++0x标记或使用gcc使用之前的标记加-lstdc++来编译代码。< / p>

然而,当我使用你的标志时,它不起作用(虽然错误是完全不同的),所以也许下次尝试使用以下标志(因为它不一定是由你编译引起的(仅) GCC配置错误。)

gcc -lstdc++ -std=c++0x -pthread your.cpp
g++ -std=c++0x -pthread your.cpp

答案 1 :(得分:0)

正如您在错误消息中看到的那样,问题不在于您的配置,而在于您的g ++选项。使用

g++ -lpthread

用于pthreads(POSIX线程)和

g++ -lboost_thread

用于提升线程。 (-pthread错了。)

参见g ++手册

man gcc
相关问题