1
votes

I am trying to use CDT to edit C++ files. However, it refuses to see the std classes like string and vector.

(I will continue to build with make outside of eclipse, for now at least. The code compiles fine. But without a definition for string etc. almost everything is shown as an error in the editor.)

I am using Luna. CDT added to a Java oriented eclipse using Help > Install New Software.

The docs just say "install the the Tool Chains and stuff happens". But having spent several hours reading up on this, I think the phrase "Tool Chain" has several different meanings depending on the sentence. These include

  • The compilers and linkers themselves, e.g. minggw
  • Extra stuff (plugin?) added to Eclipse itself so that it can use those compilers.
  • Configuration within Eclipse itself

My make file uses

D:\cygwin64\lib\gcc\x86_64-w64-mingw32\4.8.3\include

but sometimes CDT seems to be pointing to

D:\mingw64\include\c++\4.5.4

Which is OK, as it will have the same .h files.

I have tried fiddling with PATH (to /bin), plus the Project Properties > > Environment MINGW_HOME. The "tool chain editor" mentions MingGW and says GCC C++, but I don't know what that really means and the easy-to-use interface does not show the paths.

I also tried adding D:\cygwin64\lib\gcc\x86_64-w64-mingw32\4.8.3\include to the Paths & Symbols > Include, but that does not help.

There is also "Libraries and "Library Paths". I do not know what the difference is (both want paths) but I am guessing this is for linking, not compiling. I am also guessing that the IDE parsing of the C++ during editing is done by CDT itself, and does not rely on external compilers.

A secondary question is how does CDT determine which header files are relevant? In general that is undecidable in C, in my case my header files rely on other header files that are loaded from the containing .cpp files. I am guessing that it just ignores the #include directives and loads up every header file it comes across, hoping that there are no conflicts.

2

2 Answers

0
votes

My hack is as follows, after spending too much time trying to fix it properly and no posts here.

#ifdef ECLIPSE
// Dummy declarations to help with misconfigured Eclispse
  class string{};
  template <typename T>
  class vector{
  public:
      unsigned size();
      void push_back(T t);
      T at(unsigned idx);
  };
#endif

Yes, just trick Eclipse into thinking the classes are OK. I would not call this an answer though.

Strangely the class def of string seems enough to convince eclipse that casts to char * are OK.

(I access these classes with using, so no std::)

0
votes

If CDT is unable to resolve standard library includes like <string> and <vector>, this is a sign that it cannot find your compiler.

Open a Command Prompt and type g++. Is it found? If not, it means the directory containing your compiler is not in the PATH environment variable. Add this directory (likely something like D:\cygwin64\bin) to PATH (how you do this depends on your Windows version, but it's something like Computer | Properties | Advanced system settings | Environment variables), then restart Eclipse and try again.