Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse CDT cannot parse methods on elements in STL containers

I'm using Eclipse Juno with CDT to develop my C++ project with custom makefile. I am also using C++11 features, which I got to work with Eclipse's parser following advice here on SO.

The problem is that Eclipse is unable to parse methods or fields accessed on STL container elements. E.g.:

mainapp.h

typedef struct _PlayerCalibrationData {
    [...]
    std::string getSamplesStr()
    {
            [...]
    }
} PlayerCalibrationData;

std::vector<MainApp::PlayerCalibrationData> m_calibrationData;

mainapp.cpp

m_calibrationData[0].getSamplesStr();

getSamplesStr() will be underlined and marked as an error, with the message "Method 'getSamplesStr' could not be resolved".

The compiler doesn't complain, though, regardless of whether I invoke it from Eclipse or from the command line.

Also, when I type m_calibrationData., all vector methods pop up via content assist (i.e. it's not an issue of Eclipse not finding the vector include), but as soon as I access an element via [] or at(), content assist is quiet and anything typed manually is marked as an error.

Is it normal that this doesn't work? If yes, is there a way I can turn off assist/correction for template-based containers specifically?

EDIT

I now also tried disabling c++11 support, and if I do that the problem disappears -- but then of course the c++ 11 types and syntax aren't recognized.

EDIT 2

I imported a second project, entered exactly the same settings, and for this project the parsing works. The only difference is the project layout (different location of makefiles). But even if I delete and re-import the first project, it still doesn't work.

like image 949
pholz Avatar asked Oct 31 '12 08:10

pholz


1 Answers

this worked for me:

"your project name" -> right click -> properties:

C/C++ General -> Preprocessor Include Paths, Macros etc. -> switch to the tab named "Providers":

  • for "Configuration" select "Release" (and afterwards "debug")

  • switch off all providers and just select "CDT GCC Built-in Compiler Settings"

  • uncheck "Share setting entries between projects (global provider)"

  • in the "Command to get compiler specs:" add "-std=c++11" without the quotes (may work with quotes too)

  • hit apply and close the options

  • rebuild the index

this works for me on both mashines, at home and at work win7 x64, latest official eclipse with cdt mingw-w64 gcc 4.7.2 from the mingwbuilds project on sourceforge

like image 116
Andreas Avatar answered Oct 14 '22 22:10

Andreas