12

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?

Community
  • 1
  • 1
Matthijn
  • 3,126
  • 9
  • 46
  • 69
  • 1
    You think you'll be getting the C++ STD on an embedded platform? Think again. – Linuxios Dec 23 '12 at 15:11
  • I don't know, OpenWRT is a linux based system. So I guess it will be there? – Matthijn Dec 23 '12 at 15:12
  • 4
    Well, there will almost definatly be a C STD, but the C++ one might be a little intensive for a router. If you need threads and C++ isn't working, go for Linux's `pthread`. Also, why are you developing for Linux in Xcode on LLVM? You need GCC and some cross compiling. – Linuxios Dec 23 '12 at 15:13
  • The coding will be done in Xcode, the actual compiling will be done through cross-compiling indeed. I'll have a look at pthread. – Matthijn Dec 23 '12 at 20:18
  • check out http://tinythreadpp.bitsnbites.eu/ it is a drop in replacement for c++11 threads. – Justin Meiners May 28 '13 at 15:28

1 Answers1

2

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)

bartimar
  • 3,374
  • 3
  • 30
  • 51