std::thread is not a member of namespace std using Eclipse Kepler MinGW
Plain MinGW cannot support std::thread
. You will need to use a MinGW-w64 toolchain (such as those shipped with Qt 5) that has "posix" threading enabled, so that libstdc++ exposes the <thread>
, <mutex>
and <future>
functionality.
You can find an installer here, but you can also try just replacing the whole mingw
toolchain root folder with one of these packages. You can choose 32- or 64-bit, remember to select threads-posix
if you want to play with std::thread
and friends. No special compiler options other than the ones you already have are needed. I do suggest using -std=c++11
if you don't need GCC 4.6 compatibility.
Why is the Eclipse C++ symbol 'std' could not be resolved error fixed by saving the file?
Eclipse's CODAN tool runs as you type, unfortunately it only parses dependencies on demand, usually with a save.
Why? Eclipse's CODAN tool isn't exactly a gazelle, so having to track through all of the file's dependencies while the user is typing is probably a system killer. This may improve with time. In the meantime, save regularly.
And, to be honest, this is probably a dodge. It should only have to search dependencies when a dependency is added. But there are a lot of buts. What about when a dependency is added to a dependency? Or a new dependency is hidden in a macro (don't do this) and hard to parse without digging through the dependencies? Or exposed by adding a define that triggers conditional compilation (I prefer different implementation files and letting the linker sort it out to conditional compilation)? What about...?
Blah. If people want to write garbage code, that's their problem. A static analyzer should focus on the needs of people who aren't trying to trick it and circumvent good style. That said, I don't know the CODAN code, and I don't know how deep one would have to go to change it to catch and handle the easy cases at a tolerable real-time rate.
But at the end of the day, the only analyzer you should pay attention to is the compiler--with the warning levels turned up to 11, of course. CODAN is not perfect. It misses and misinterprets stuff, and you may find yourself hunting a bug that's not a bug in your code. If the compiler has a bug, that's a different case, but a lot less likely. Definitely take CODAN's help, but before you spend time on an odd error, make sure it really is an error by saving and building the program.
CODAN configuring stuff:
Most of CODAN's options can be found by visiting Project->Properties on the menu and navigate the Properties dialogue to C/C++ General->Code Analysis
To turn configure CODAN's run options, to turn off updating as you type for example, go one step further to C/C++ General->Code Analysis->Launching
You will also find that if you are editing included headers in another project, you will have to force an index rebuild to to catch the modifications. Select Project->C/C++ Index->Rebuild from the menu for the project doing the including.
cross-compiling c++11 threads with mingw on linux
There is already a native implementation of std::thread and sync primitives, that works with any C++11 version of MinGW:
https://github.com/meganz/mingw-std-threads
Eclipse/MinGW issue with C++ User-defined Literals
You need to enable CDT does to recognize C++11 features. If you did that it's likely a bug in the CDT scanner and you should try to report a bug
Type 'std::default_random_engine' could not be resolved
UPDATE: It's been a long time since I posted the original answer and it has become outdated. I double-checked today (Mar 15, 2014): in Eclipse Kepler (Build id 20130614-0229) it is sufficient to
add under Project > Properties > C/C++ Build > Settings then on the Tool Settings tab GCC C++ Compiler > Miscellaneous the
-std=c++11
flag,then under Window > Preferences > C/C++ > Build > Settings on the Discovery tab chose CDT GCC Built-in Compiler Settings and add the
-std=c++11
flag to Command to get compiler specs. On my machine it looks like this after the change:${COMMAND} -E -P -v -dD -std=c++11 "${INPUTS}"
clean and rebuild both your project and your index (Project > C/C++ Index > Rebuild) as Eclipse tends to cache error messages and show them even though they are gone after changing the settings.
This works on my machine for sure. If it doesn't on yours, then you might want to give a shot to this: C++11 full support on Eclipse although I am neither sure about the correctness of this approach nor was it necessary to do it on my machine. As of March 7, 2014 users claim that it helped them whereas the above approach didn't.
The original post, now outdated:
It seems to be a false error from the IDE.
Click on the project properties, then C/C++ General > Code Analysis > Syntax and Semantic Errors and deselect Type cannot be resolved.
I also had to disable a bunch of other Syntax and Semantic Errors, such as Invalid arguments, Invalid overload, Symbol is not resolved, etc. in my own projects. These bogus errors come from Codan.
(You might have to add __GXX_EXPERIMENTAL_CXX0X__
to your defines / preprocessor macros, not sure about this one though.)
Related Topics
Treating Memory Returned by Operator New(Sizeof(T) * N) as an Array
Convert a Single Color with Cvtcolor
Do I Need to Protect Read Access to an Stl Container in a Multithreading Environment
Can C++ Have Code in the Global Scope
How to Pass a Vector of Strings to Execv
Constructor Invocation Mechanism
How to Pause a Pthread Any Time I Want
Loop Until Integer Input Is in Required Range Fails to Work with Non-Digit Character Inputs
Matlab VS C++ VS Opencv - Imresize
Opencv Unable to Set Up Svm Parameters
Why Callback Functions Needs to Be Static When Declared in Class
How to Use Sort() in C++ with Custom Sort Member Function
When to Make a Type Non-Movable in C++11
What Is the C++ Function to Raise a Number to a Power
Is There Any Alternative to Using % (Modulus) in C/C++
Getting the MAChine Serial Number and CPU Id Using C/C++ in Linux