XCode std :: thread C ++ [英] XCode std::thread C++

查看:184
本文介绍了XCode std :: thread C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个学校的小项目,我需要创建一个简单的客户端/服务器构建,它将运行在路由器(使用openWRT),我想在这个应用程序中做线程。



我的C ++技能非常有限,所以我在上找到了这一点互联网作为基本示例。

  #include< thread> 
#include< iostream>

void doSomeWork(void)
{
std :: cout< hello from thread ...< std :: endl;
return;
}

int main(int argc,char * argv [])
{
std :: thread t(doSomeWork);
t.join();
return 0;
}



当我尝试在Xcode(4.5.2)以下错误:


尝试使用已删除的函数



$ b b

它显示了一些代码:

  __ threaad_execute(tuple <_Fp,_Args ...& __t ,__tuple_indices< _Indices ...>)
{
__invoke(_VSTD :: move(_VSTD :: get< 0>(__ t)),_VSTD :: move(_VSTD :: get< _Indices> (__t))...);
}



我想我需要做'build settings'或'link library ' 或者其他的东西?但我不知道该怎么做。我认为我可能需要设置以下设置:(我在这里找到)




  • 在项目的Build Settings选项卡中,向下滚动到Apple LLVM Compiler 4.1 - Language

  • 设置C ++语言方言到C ++ 11 [-std = c ++ 11]

  • 将C ++标准库设置为libc ++ )



但已设置的设置。



在XCode中使用G ++而不是LLVM。

不要忘记在编译器构建设置中链接线程库(-lpthread或-pthread,-lrt)。并计算与Win / Mac / Linux操作系统(尽管它是POSIX)


的线程行为的差异

For a small project for school I need to create a simple client / server construction which will run on a router (with openWRT) and I am trying to do something with threads in this application.

My C++ skills are very limited, so I found this on the internet as an basic example.

#include <thread>
#include <iostream>

void doSomeWork( void )
{
    std::cout << "hello from thread..." << std::endl;
    return;
}

int main( int argc, char *argv[] )
{
    std::thread t( doSomeWork );
    t.join();
    return 0;
}

When I try to run this in Xcode (4.5.2) I get the following error:

Attempt to use an deleted function

And it shows some code of:

__threaad_execute(tuple<_Fp, _Args...>& __t, __tuple_indices<_Indices...>)
{
    __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
}

I think I need to do something with 'build settings' or 'link library' or something? But I am not quite sure what to do exactly. I thought I might need to set the following settings (which i found here)

  • In the Build Settings tab for your project, scroll down to "Apple LLVM Compiler 4.1 - Language"
  • Set the setting "C++ Language Dialect" to "C++11 [-std=c++11]"
  • Set the setting "C++ Standard Library" to "libc++ (LLVM standard C++ library with C++11 support)"

But those settings where already set.

Is there any flag / library or something I am missing?

解决方案

Use G++ instead of LLVM in XCode. Don't forget to link thread libs (-lpthread - or -pthread, -lrt) in compiler build settings. And count with the differences of thread behaviour across Win/Mac/Linux OS (despite it's POSIX)

这篇关于XCode std :: thread C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆