'Eclipse not finding std c++ libraries

I have a Windows8 machine with mingw installed in c:\mingw Eclipse does successfully compile programs, but it considers lines to contain errors that are fine when compiled. Eclipse is not finding the libraries itself.

When I first build a project in eclipse with the CDT components install, it shows errors on every #include and every line using an object.

Example:

#include <iostream>
using namespace std;

int main() {
  cout << "hello\n";
}

The above code shows errors on the include, the using and the cout << line. I can get rid of the errors by clicking: project->properties C++/General Preprocessor Include Then on the providers tab, I can check off "CDT Build output parser" and fix the mistakes as described by the first answer below, which I am upchecking. But this only works for the project. I have to do this every time. How can I get eclipse to simply accept standard C++ EVERY TIME I build a new project without reconfiguring each project?

I have been able to stop errors on the includes by going into project settings and adding the directories:

c:/bin/mingw/lib/gcc/include ...

That leaves the errors on lines using the objects.

#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main() {
    string s = "this is a test.";
    regex e("est");
    smatch m;

The line with regex still shows an error: "type regex could not be resolved" even though the code compiles and the regex include is recognized.

Additionally, on a different machine running windows 8.1 with Mingw installed, eclipse will not debug. Is there some document on how to connect Eclipse CDT to the library?



Solution 1:[1]

While you obviously successfully compile the code with gcc from within Eclipse, Eclipse has its own built-in C++ parser and you need to separately let it know that you are using C++11.

Add the -std=c++11 option to the CDT GCC Builtin Compiler Settings under Project propierties -> C/C++ General -> Preprocessor Include Paths, the compiler specs should look similar to this:

${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11 

UPDATE. Please read Setting Up Include Paths and Macros for C/C++ Indexer to understand how CDT automatic discovery of include paths and preprocessor symbols (aka Scanner Discovery) for supported tool chains is applicable to you.

The gist is that the CDT uses the Language Settings Providers to find include paths and preprocessor symbols. And Language Settings Providers can be configured on project properties page "Preprocessor Include Paths, Macros, etc."

Once you have proper settings you can make them a template workspace and just copy the template workspace over for your new projects, or alternatively have a script that will set up just the relevant settings. Also see: Setting preferences for all Eclipse workspaces.

Solution 2:[2]

I have had the same problem. Eclipse underlined like an error a regex keyword, but project was built without errors. I chose a Language Dialect as "ISO C++1y (-std=c++1y)" in Properties->C/C++ Build->GCC C++ Compiler->Dialect Language Standart

Solution 3:[3]

Been a while, but adding in case someone else finds this answer as I did.

I had what appeared to be this issue but it turned out that while I had installed MinGW, eclipse still expected me to have installed cygwin. Go to project properties > C/C++ Build > Tool Chain Editor > Current Toolchain and select the appropriate option. Not sure why it defaults the setting to a toolchain it can't find.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Dmytro Bilovol
Solution 3 Andy