gpt4 book ai didi

c++ - gcc 4.5.1 为 C++0x 线程支持配置选项

转载 作者:太空狗 更新时间:2023-10-29 23:20:09 25 4
gpt4 key购买 nike

我正在尝试为支持 C++0x 线程的 cygwin 编译 gcc 4.5.1。但是,生成的 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?

最佳答案

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

g++ -lpthread

用于 pthreads(POSIX 线程)和

g++ -lboost_thread

用于增强线程。 (-pthread 是错误的。)

看g++的手册

man gcc

关于c++ - gcc 4.5.1 为 C++0x 线程支持配置选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3553630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com