Error thread is not a member of std

MinGW не видит класс thread C++ Решение и ответ на вопрос 2020728

120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

1

25.07.2017, 15:26. Показов 10827. Ответов 21


MinGW не видит класс thread,в то время как заголовочный файл thread подключается без проблем.При создании потока:Thread thr(f); появляется ошибка Thread: was not declared in this scope. Компилирую так:

Код

g++ main.cpp -omain.exe -std=c++11 -pthread

OC:Windows 7,MinGW устанавливал с оф. сайта



0



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 15:32

2

std::thread, а не Thread.



1



GreyCat

120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

25.07.2017, 16:22

 [ТС]

3

в первом первом посте писал от руки,вот точный код:

C++
1
2
3
4
5
6
7
8
#include <thread>
void getMessage(int arg){
 
}
int main() {
 std::thread thr(getMessage,4);
  return 0;
}

и сообщение об ошибке:

Код

C:Usersuser>g++ C:UsersuserDesktopclient.cpp -oC:UsersuserDesktopclien
t.exe -std=c++11 -pthread
C:UsersuserDesktopclient.cpp: In function 'int main()':
C:UsersuserDesktopclient.cpp:6:2: error: 'thread' is not a member of 'std'
  std::thread thr(getMessage,4);



0



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 17:38

4

GreyCat, mingw с posix-thread?



1



120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

25.07.2017, 21:22

 [ТС]

5

эмм,я даже не знаю,говорю же стандартная)



0



3433 / 2812 / 1249

Регистрация: 29.01.2016

Сообщений: 9,426

25.07.2017, 21:34

6

Цитата
Сообщение от GreyCat
Посмотреть сообщение

я даже не знаю,говорю же стандартная)

Название сборки mingw (типа: x86_64-7.1.0-release-win32-seh-rt_v5-rev0), которую скачал, осталась?



1



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 21:43

7

GreyCat, выхлоп g++ -v покажите.



1



79 / 67 / 28

Регистрация: 22.04.2016

Сообщений: 384

25.07.2017, 21:46

8

Сейчас ради интереса попытался скомпилировать код ТС. Также выдало ошибки.

Цитата
Сообщение от Croessmah
Посмотреть сообщение

выхлоп g++ -v покажите.

У меня такой выхлоп:

Код

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Program Files/mingw-w64/i686-7.1.0-win32-dwarf-rt_v5-rev0/mingw32/bin/../libexec/gcc/i686-w64-mingw32/7.1.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-7.1.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw710/i686-710-win32-dwarf-rt_v5-rev0/mingw32 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-sjlj-exceptions --with-dwarf2 --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw710/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw710/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw710/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw710/prerequisites/i686-w64-mingw32-static --with-pkgversion='i686-win32-dwarf-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/i686-710-win32-dwarf-rt_v5-rev0/mingw32/opt/include -I/c/mingw710/prerequisites/i686-zlib-static/include -I/c/mingw710/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw710/i686-710-win32-dwarf-rt_v5-rev0/mingw32/opt/include -I/c/mingw710/prerequisites/i686-zlib-static/include -I/c/mingw710/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw710/i686-710-win32-dwarf-rt_v5-rev0/mingw32/opt/include -I/c/mingw710/prerequisites/i686-zlib-static/include -I/c/mingw710/prerequisites/i686-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw710/i686-710-win32-dwarf-rt_v5-rev0/mingw32/opt/lib -L/c/mingw710/prerequisites/i686-zlib-static/lib -L/c/mingw710/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: win32
gcc version 7.1.0 (i686-win32-dwarf-rev0, Built by MinGW-W64 project)



1



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 21:50

9

igdev, в папочке с бинарниками есть i686-w64-mingw32-g++-win32, i686-w64-mingw32-g++-posix или подобное?



1



120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

25.07.2017, 21:51

 [ТС]

10

Код

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/5.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=m
ingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i58
6 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-sha
red --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-sp
ecific-runtime-libs --with-libintl-prefix=/mingw --enable-libstdcxx-debug --with
-tune=generic --enable-libgomp --disable-libvtv --enable-nls : (reconfigured) ..
/src/gcc-5.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mi
ngw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-language
s=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-thread
s --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs
 --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-d
ebug --with-tune=generic --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 5.3.0 (GCC)



0



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 21:57

11

Лучший ответ Сообщение было отмечено GreyCat как решение

Решение

GreyCat, я не в курсе, как для win32 решить, ибо не пользуюсь.
Может кто еще что подскажет.

А можете скачать mingw отсюда:
x64
x32
выберите версию, далее модель потоков — threads-posix, затем модель исключений (seh для x64, dwarf для x32, хотя это опционально).



4



79 / 67 / 28

Регистрация: 22.04.2016

Сообщений: 384

25.07.2017, 22:16

12

Croessmah, Есть просто i686-w64-mingw32-g++

Добавлено через 13 минут
Croessmah, В чем отличие модели потоков posix и win32?



1



120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

25.07.2017, 22:20

 [ТС]

13

какую модель исключений следует выбрать?
У меня система 32 разрядная,возможно ли установить mingw 86_64?



0



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

25.07.2017, 22:21

14



2



120 / 4 / 1

Регистрация: 15.06.2016

Сообщений: 236

25.07.2017, 22:38

 [ТС]

15

но там нет про модель исключений и архитектуру



0



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

26.07.2017, 00:17

16

Цитата
Сообщение от GreyCat
Посмотреть сообщение

У меня система 32 разрядная,возможно ли установить mingw 86_64?

Что-то я сомневаюсь, но мало ли…

Цитата
Сообщение от GreyCat
Посмотреть сообщение

но там нет про модель исключений

В сообщение выше я вносил правки:

Цитата
Сообщение от Croessmah
Посмотреть сообщение

далее модель потоков — threads-posix, затем модель исключений (seh для x64, dwarf для x32, хотя это опционально).



1



Заклинатель змей

611 / 508 / 213

Регистрация: 30.04.2016

Сообщений: 2,412

26.07.2017, 02:43

17

GreyCat,

Не по теме:

не проще ли поставить VS или сразу Линукс и не париться с MinGW



1



Antikl

с++

1282 / 523 / 225

Регистрация: 15.07.2015

Сообщений: 2,562

26.07.2017, 04:50

18

Цитата
Сообщение от GreyCat
Посмотреть сообщение

C
1
g++ main.cpp -omain.exe -std=c++11 -pthread

я так делаю и работает

C++
1
g++ main.cpp -o main.exe -std=c++11 -pthread

вот такой код, он простой ну для примера сгодиться

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <string>
#include <iostream>
#include <thread>
 
using namespace std;
 
// The function we want to execute on the new thread.
void task1(string msg)
{
    cout << "task1 says: " << msg;
}
 
int main()
{
    // Constructs the new thread and runs it. Does not block execution.
    thread t1(task1, "Hello");
 
    // Makes the main thread wait for the new thread to finish execution, therefore blocks its own execution.
    t1.join();
}



1



Don’t worry, be happy

17781 / 10545 / 2036

Регистрация: 27.09.2012

Сообщений: 26,516

Записей в блоге: 1

26.07.2017, 05:46

19

Antikl, mingw может быть собран без posix-потоков (как у ТС), там такое не прокатит.



2



с++

1282 / 523 / 225

Регистрация: 15.07.2015

Сообщений: 2,562

26.07.2017, 06:18

20

Цитата
Сообщение от Croessmah
Посмотреть сообщение

Antikl, mingw может быть собран без posix-потоков (как у ТС), там такое не прокатит.

а ну тогда понятно,



1



Operating System: Windows XP SP3
Compiler: MinGW g++ 4.7.2
Code:

1
2
3
4
5
6
7
8
9
#include <thread>

void g() {}

int main() {
   std::thread t(g);
   
   return 0;
}

Commands:

mingw32-g++.exe -Wall  -O2  -std=c++11    -c "C:ProgrammingThread Practicemain.cpp" -o objReleasemain.o

Errors:

C:ProgrammingThread Practicemain.cpp||In function 'int main()':|
C:ProgrammingThread Practicemain.cpp|6|error: 'thread' is not a member of 'std'|
C:ProgrammingThread Practicemain.cpp|6|error: expected ';' before 't'|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 2 seconds) ===|

After doing some research, apparently MinGW still doesn’t have a port for the threads library for Windows. Has anyone gotten this to work yet?

Use Boost library instead, it has almost the same syntax.

I’m aware of the boost libraries, and I have already used boost::thread as well. However, I recently deleted all of my boost stuff and am trying to stick with the standard. I deal with a lot of hassles, one less compiler command or library I need to include would be a god send. I also don’t want to go through the process of putting boost back on my system (I’m running low on HDD space) just for threads (I know there is a bunch of other stuff, but most has been implemented in C++11, and the rest I don’t foresee myself using anytime in the near future).

Then you either use another compiler (maybe VS2012 supports c++ 11 threads — but if you run XP you cannot use it) or you do not use C++11 features at all.

MinGW for example does not even fully supports Unicode these days (just an example)

Last edited on

I can’t even install VS2012 on my computer due to hardware limitations (MS’s excuse, not mine).

I’ve been able to use every other C++11 feature that I’ve tried so far (I have numerous examples on this forum). I’m just saddened that MinGW hasn’t implemented threads for Windows yet.

I was not aware it didn’t fully support Unicode yet, but like what specifically? I don’t use Unicode nearly at all, but it would be nice to know what’s actually limited.

Maybe once I free up some more space, I’ll put boost back on my computer, or I’ll switch to my Linux partition and just practice threads there. I just like a one place stop to do everything I need. Are you aware if the Cygwin port uses threads?

Nothing is stopping you to use _beginthreadex() from process.h, it is available in MinGW too and is not a C++11 feature.

MinGW support Unicode if you use -municode switch (only recent versions) for wWinMain (GUI applications), but even then there is no support for console applications built for Unicode (wmain entry point). You will get a linker error if you try to do that.

Last edited on

I hate using C, but there is no alternative for Windows at the moment. I also hate the WinAPI. So far, it looks like process.h requires both. Is this true concurrency? Looking at some examples (takes me a while to completely understand what’s going on since I’m not familiar with C), I’m trying to follow how it works.

So far I’m understanding that beginthread returns a handle to said thread, and endthread needs to be written into the function that is going to be a thread. This is a little different than what I was thinking. I’m reading the information from here http://www.digitalmars.com/rtl/process.html but I’m kind of confused. What’s the difference between _beginthread and _spawn? spawn looks like it might be the better choice, but maybe I missed something when reviewing it. I also didn’t see _beginthreadex() anywhere on that page. Maybe it’s too old?

I’m also assuming that I’ll have to wrap any variables into their own thread safe class to prevent them from being accessed while being used. I’m just trying to get a grasp of this before I jump head first into coding since C isn’t a strong point for me at all.

Edit: Did some digging on SO, and found more information between _beginthread() and _beginthreadex(). I am most definitely using the later, however, I need to research the «security» parameter. Ugh.

Last edited on

Last edited on

tdm doesn’t seem to have std::thread support

C:UsersSeanDownloads>mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=mingw32-g++
COLLECT_LTO_WRAPPER=c:/mingw32/bin/../libexec/gcc/mingw32/4.7.1/lto-wrapper.exe
Target: mingw32
Configured with: ../../src/gcc-4.7.1/configure --build=mingw32 --enable-language
s=c,c++,ada,fortran,objc,obj-c++ --enable-threads=win32 --enable-libgomp --enabl
e-lto --enable-fully-dynamic-string --enable-libstdcxx-debug --enable-version-sp
ecific-runtime-libs --with-gnu-ld --disable-nls --disable-win32-registry --disab
le-symvers --disable-build-poststage1-with-cxx --disable-werror --prefix=/mingw3
2tdm --with-local-prefix=/mingw32tdm --enable-cxx-flags='-fno-function-sections
-fno-data-sections' --with-pkgversion=tdm-1 --enable-sjlj-exceptions --with-bugu
rl=http://tdm-gcc.tdragon.net/bugs
Thread model: win32
gcc version 4.7.1 (tdm-1)

Same with nugen

C:MinGW>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.7.2/lto-wrappe
r.exe
Target: i686-pc-mingw32
Configured with: ../src/configure --prefix=/c/temp/gcc/dest --with-gmp=/c/temp/g
cc/gmp --with-mpfr=/c/temp/gcc/mpfr --with-mpc=/c/temp/gcc/mpc --enable-language
s=c,c++ --with-arch=i686 --with-tune=generic --disable-libstdcxx-pch --disable-n
ls --disable-shared --disable-sjlj-exceptions --disable-win32-registry --enable-
checking=release --enable-lto
Thread model: win32
gcc version 4.7.2 (GCC)

They both give this error


C:UsersSeanDownloads>g++ thread.cpp
thread.cpp: In function 'int main()':
thread.cpp:6:2: error: 'thread' is not a member of 'std'
thread.cpp:6:14: error: expected ';' before 't'
thread.cpp:6:55: error: expected primary-expression before ')' token
thread.cpp:6:55: error: expected ';' before ')' token

With this code

1
2
3
4
5
6
7
8
#include <iostream>
#include <thread>

int main()
{
	std::thread t([](){std::cout<<"hello from thread 2";});
	std::cout<<"hello from thread 1"<<std::endl;
}

Last edited on

</3 <— My hopes of using C++11 Threads.

Sigh, this isn’t going to be easy, but it’ll be one more thing, like STL list, that I can add to my arsenal of code. I’m starting to understand MSDN on this one (first article I might have ever understood in it’s entirety)…wait…does that mean I’m actually learning to think properly?

You can do what I do and simply swap out std::thread with boost::thread. The APIs for each are 100% identical as far as I’ve been able to tell (I’ve been using my C++11 reference when writing boost code and it hasn’t failed me yet)

You can also hide the namespace you’re using so that it can be easily swapped out if/when you use a compiler that supports std::thread.

1
2
3
namespace thd = boost;  // or = std if std::thread is supported

thd::thread  yourthread(...);

Sounds like a plan. I’m just so disappointed in MinGW about this whole thing. It supports threads, uses Win32 threading, but it doesn’t exist to be used…

I also believe I’m going to be taking a break from programming to work on learning some more of my scripting language. My scripts are in high demand all of a sudden.

I know I’ve successfully compiled some projects using std::thread for Windows before. I recall that it was indeed not TDM, but a 4.7 nightly. Either it had special patches or std::thread (or rather, gthread) support was removed before the final release. Either way, it’s frustrating.

Besides using boost as a drop-in, these patches might be worth a try:
http://tehsausage.com/mingw-std-thread-gcc-4-7
The advantage is that they wouldn’t require building MinGW yourself.

I tried the patches and using the same code as above (and used the suggested libraries) I get this:

terminate called without an active exception

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Process returned 3 (0x3)   execution time : 0.172 s
Press any key to continue.

Now, it’s very possible I did something wrong, but from reading it, it seems pretty straight forward. I’m wondering if it’s not compatible with 4.7.2. What version did you use? 4.7.0?

There was also a note about MinGW64 threads being more compatible, but I have a 32bit system. I won’t be able to use a 64 bit compiler, will I?

I’m also having std::thread problems with gcc-4.7.2 in linux. This code compiles and runs with boost but not std thread.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <thread>
//#include <boost/thread.hpp>

namespace thrd = std;

int main()
{
	thrd::thread t([](){std::cout<<"thread2"<<std::endl;});
	std::cout<<"thread1"<<std::endl;
	t.join();
}

Using std::thread gives this output.

sean@sean-virtual-machine:~/Desktop$ g++ --std=c++0x thread.cpp
sean@sean-virtual-machine:~/Desktop$ ./a.out 
terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted
Aborted (core dumped)

So it looks like for now, for me at least, it’s VS2012 or boost for threading.

Last edited on

It compiles fine with MinGW, but I’m not sure if you need to link to a library on Linux or not. Maybe someone here can enlighten us.

on Linux you get operation not permitted from gcc when you forget -pthread.

Last edited on

Thank you Cubbi, I didn’t realize that was necessary for std::thread.

It’s just a gcc quirk. Intel requires -pthread just like gcc, but produces a more meaningful message («Enable multithreading to use std::thread), and Clang++ works without any special switches.

Topic archived. No new replies allowed.

Topic: why no std::thread?  (Read 25992 times)

I guess why code::blocks used a GCC package with no thread support under windows.

If I try to compile the following:

#include <iostream>
#include <thread>

void foo(){
std::cout<<«hello thread»<<std::endl;
}

int main(){
    std::thread myT(foo);
    myT.join();
    return 0;
}

I get the error «thread is not a member of std»

I already have the flag
«-std=C++11»
in compile options.

« Last Edit: April 21, 2013, 09:49:52 pm by demone »


Logged

processor: Intel Core 2 Quad.
ram: 4 GB
os: Vista
gfx card: Ati Radeon HD 5570


the TDM mingW port indeed does not support std::thread, short : LGPL issues and so on.


Logged


oh my bad :( that’s really freaking. Ok I have than to swap to Linux partition.
is there any chance to add support for std::thread ever in GCC at this point?


Logged

processor: Intel Core 2 Quad.
ram: 4 GB
os: Vista
gfx card: Ati Radeon HD 5570


oh my bad :( that’s really freaking. Ok I have than to swap to Linux partition.
is there any chance to add support for std::thread ever in GCC at this point?

That’s not the right place to ask.
We do not build vompilers just an IDE, that works with many compilers.
We ship with a TDM’s gcc on windows to make it easy to start coding for beginners (and most other users) without the need to explicitely download a compiler.

So you as user are free to use any supported compiler, with or without std:thread-support.


Logged


We do not build vompilers just an IDE, that works with many compilers.

That sounds scary… if I install one, will it suck the blood from my computer? ;)


Logged


That sounds scary… if I install one, will it suck the blood from my computer? ;)

You’ve never heard of garlic AV suite? The first AV solution at all?

— osdt


Logged


zabzonk


Logged



Logged

processor: Intel Core 2 Quad.
ram: 4 GB
os: Vista
gfx card: Ati Radeon HD 5570



Logged

Regards,
xunxun


Я скомпилировал и установил gcc4.4 с помощью macports.

Когда я пытаюсь скомпилировать с помощью -> g ++ -g -Wall -ansi -pthread -std = c ++ 0x main.cpp …:

 #include <thread>
 ...
  std::thread t(handle);
  t.join();
 ....

Компилятор возвращает:

 cserver.cpp: In member function 'int CServer::run()':
 cserver.cpp:48: error: 'thread' is not a member of 'std'
 cserver.cpp:48: error: expected ';' before 't'
 cserver.cpp:49: error: 't' was not declared in this scope

Но std::cout <<... компилируется нормально ..

Может кто-нибудь мне помочь?

3 ответы

gcc пока не полностью поддерживает std :: thread:

http://gcc.gnu.org/projects/cxx0x.html

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html

Используйте boost :: thread в это время.

Редактировать

Хотя следующее скомпилировано и отлично работает с gcc 4.4.3:

#include <thread>
#include <iostream>

struct F
{
  void operator() () const
  {
    std::cout<<"Printing from another thread"<<std::endl;
  }
};

int main()
{
  F f;
  std::thread t(f);
  t.join();

  return 0;
}

Скомпилировано с

g ++ -Wall -g -std = c ++ 0x -pthread main.cpp

Выход a.out:

Печать из другого потока

Вы можете предоставить полный код? Может быть, в этих ...s?

ответ дан 26 мар ’10, в 03:03

Падение -анси, это означает -std = c ++ 98, что вам явно не нужно. Это также вызывает макрос __STRICT_ANSI__ должны быть определены, и это может изменить поведение заголовков, например, отключив поддержку C ++ 0x.

ответ дан 26 мар ’10, в 14:03

У меня была такая же проблема с окнами с использованием MinGW. Я нашел классы-оболочки для in на github mingw-std-нитки Включение файлов mingw.mutex.h, mingw.thread.h в глобальный каталог MinGW решило эту проблему. Все, что мне нужно было сделать, это включить файл заголовка, и мой код остался прежним.

#include "mingw.thread.h"

...
std::thread t(handle);
...

Создан 30 ноя.

Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками

c++
multithreading
gcc
c++11
std

or задайте свой вопрос.

priema

Posts: 5
Joined: Sat Jan 24, 2015 4:35 pm

c++11 required? thread not a member of std error

hy everyone ..
when i want to execute the following code i got this error:
g++ -std=c++0x test.cpp -lpthread
test.cpp: In function ‘int main(int, char**)’:
test.cpp:43:5: error: ‘thread’ is not a member of ‘std’
test.cpp:43:17: error: expected ‘;’ before ‘t’

i also tried it with -std=c++11 but then i got this error :
unrecognized command line option ‘-std=c++11’

i’m running on raspbian

my program:

Code: Select all

void Test::test() {
    cout << "yippie it works " << endl;
}

int main(int, char**)
{
    Test t1{3};
    std::thread t(test);
}

Does someone know what i’m doing wrong?

thank you! :D


User avatar

Paeryn

Posts: 3531
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: c++11 required? thread error

Mon Jan 26, 2015 5:51 pm

What #include are you using? For C++11 threads you need to use

Also, you’ll need to use -pthread when linking, not -lpthread

Code: Select all

$ g++ -std=c++0x test.cpp -pthread

As for why g++ on the RPi wants -std=c++0x, that was the name used before it was finalized, newer versions of gcc will accept c++11 as the name. There may be a few things different but mostly they are the same.

She who travels light — forgot something.
Please note that my name doesn’t start with the @ character so can people please stop writing it as if it does!


priema

Posts: 5
Joined: Sat Jan 24, 2015 4:35 pm

Re: c++11 required? thread error

Mon Jan 26, 2015 7:09 pm

Paeryn wrote:What #include are you using? For C++11 threads you need to use

Also, you’ll need to use -pthread when linking, not -lpthread

Code: Select all

$ g++ -std=c++0x test.cpp -pthread

As for why g++ on the RPi wants -std=c++0x, that was the name used before it was finalized, newer versions of gcc will accept c++11 as the name. There may be a few things different but mostly they are the same.

yeah thx .. i forgot to include it

thank you very much :)


Return to “C/C++”

Понравилась статья? Поделить с друзьями:
  • Error this username is already registered please choose another one
  • Error this statement may fall through werror implicit fallthrough
  • Error this server is already on your list ok
  • Error this script needs bsddb3 to be installed
  • Error this script must be started from web server s document root