无法解析命名空间成员"线程"
Can't resolve namespace member 'thread'
我想用标准的C 线程而不是UNIX练习,但是很快就会遇到问题,每当我编写 std::thread
clion用红色强调它并说无法解析名称空间'thread'Thread'。我检查了CMAKE文件,该文件设置为C 11。我重新安装了最新版本的MingW(6.3.0(,并用G 编译器打勾。我的朋友告诉我,他使用Cygwin,一切都起作用。但是,是否可以使其与mingw一起使用?
#include <iostream>
#include <thread>
#define BUFFER_SIZE 3
#define PROD_NUM 3
#define CONS_NUM 2
void produce(){
//production
}
void consume(){
//consumption
}
int main() {
std::cout << "Hello, World!" << std::endl;
int i,j;
std::thread producer(produce);
std::thread consumer (consume);
return 0;
}
代码本身几乎没有
编辑在线程库中有
#pragma GCC system_header
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
#include <chrono>
#include <functional>
#include <memory>
#include <cerrno>
#include <bits/functexcept.h>
#include <bits/functional_hash.h>
#include <bits/gthr.h>
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @defgroup threads Threads
* @ingroup concurrency
*
* Classes for thread support.
* @{
*/
/// thread
class thread
{
public:
// Abstract base class for types that wrap arbitrary functors to be
// invoked in the new thread of execution.
struct _State
{
virtual ~_State();
virtual void _M_run() = 0;
};
您是否可以确保库是否在Clion工具链中可用?例如,Cygwin确实具有包括。
clion在无法将码链接到库时显示红色的事物。它可能是主机环境变量错误。确保您的CMakeLists.txt
正在工作,并且环境变量,标准库链接以及编译器设置正确。编译器版本和标准库兼容。(例如,您正在使用跨编译器(RASPI,Android(,但环境VARS显示主机库等将使它失败(
检查此相关帖子,可能会有所帮助。
c 11 std ::螺纹vs posix threads
好的,所以我终于解决了问题。我安装了Cygwin,并在Clion设置中我手动链接了C/C 编译器(由于某种原因,Clion无法自动检测它们(。清除了所有人并重新索引了该项目。现在它显示没有错误,并且代码编译。
关于mingw,我在cplusplus.com上阅读了一些有关此问题的文章,但它们是关于mingw的先前版本,据说他们终于修复了它,但是我告诉我:不,他们没有。这里有一个不错的存储库,其读数文件表明Win32的线程依赖于Gthreads,但是我在库中发现了Gthread文件,一切似乎都还好...因此仍然需要调查问题。如果您了解更多,请在这里写下您的想法和经验。
目前解决方案是cygwin,使用它代替mingw。
P.S。感谢@killzonekid链接
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 如何将类的成员函数传递给线程
- 成员变量在多线程 C++ 时自行更改
- 线程消息传递或更好:在"大师班"中访问其他班级的成员
- 非静态成员失败的线程调用函数
- 将类成员函数作为线程调用到另一个类成员函数时发出警告消息
- 锁定来自其他线程的类成员
- C++多线程程序:变量定义为类成员的隔离错误
- 当我在C++中调用 struce 的只读静态成员时,线程是否安全
- 线程不是 std c++ 的成员
- 多个线程可以读取同一个类成员变量吗?
- std::使用类成员函数创建线程 - 最佳实践
- std::mutex作为一个成员变量对多个线程来说是安全的吗
- 线程中的成员函数指针
- 多线程处理中的静态成员变量
- 使用 std::thread & std::bind 在成员函数中启动线程
- 无法解析命名空间成员"线程"
- 线程池 - 如何在成员线程完成后删除工作线程(此)
- 安全地移动在访问其他成员的成员线程中运行 lambda 的对象