2

I am facing a lot of red crosses saying Symbol 'array' could not be resolved, with code that is building fine.

#include <math.h>
#include <array>
#include <sstream>
#include <string>

static std::string printArray(std::array<double, 3> data) {
  std::ostringstream strs;
  strs << "( " << data[0] << " " << data[1] << " " << data[2] << " )";
  return strs.str();
}

static std::string printVector(std::vector<double> data) {
  std::ostringstream strs;
  strs << "( " ;
  for (const auto & value : data )
      strs << value << " ";
  strs << " )";
  return strs.str();
}

The c++11 feature are activated using the -std=c++11 flag under C/C++ General -> Preposcessor Include Path, Macros etc. -> Porvides -> CDT GCC Built-in Compiler Settings as described here or here.

My question is no duplicate, since it works for std::vector and other c++11 features are handled correctly.

The header (#include <array>) can be resolved by pressing F3.

I am using Eclipse the CDT Version: Neon.3 Release (4.6.3).

schorsch312
  • 5,553
  • 5
  • 28
  • 57
  • I dont't get any errors during the build. I am using a Makefile based build. – schorsch312 Oct 12 '17 at 08:33
  • @VT, I think it is no dublicate. I did the steps suggested there. They work for `std::vector` but not for `std::array`. – schorsch312 Oct 12 '17 at 08:35
  • The [accepted answer](https://stackoverflow.com/a/9135135/440558) in the question you link to for setting the `-std=c++11` flag, it doesn't mention "Preposcessor[sic] Include Path, Macros etc." – Some programmer dude Oct 12 '17 at 08:36
  • Have you tried rebuilding Index? – user7860670 Oct 12 '17 at 08:38
  • @Someprogrammerdude: The position of the setting changed from the version Eclipse Indigo 20110615-0604 used in the answer to neo3, which I am using. – schorsch312 Oct 12 '17 at 08:39
  • @VTT Yes I have rebuild the index. You have no choice after changing the settings there. I also restarted eclispe, just to be sure. – schorsch312 Oct 12 '17 at 08:40
  • The fact that `std::vector`, without any template arguments after it (in the parameter `std::vector data`), **is** resolved, is very suspicious, since `std::vector` is a template type. You said your code compiles, but I don't see how. Can you explain? – HighCommander4 Oct 12 '17 at 17:49
  • @HighCommander4 sorry something went wrong, when coping the code here. I corrected the code. – schorsch312 Oct 13 '17 at 06:29
  • When you open the `` header via F3, do you see a preprocessor condition along the lines of `#if __cplusplus < 201103L`? Where, if that's true, a warning header is included, otherwise you get the actual contents of the header, including the definition of `std::array`? CDT should show you which of those two preprocessor branches it believes to be active, by greying out the inactive one. Which part is greyed out? – HighCommander4 Oct 13 '17 at 15:14

2 Answers2

2

I had the exact same symptoms that the OP reported:

  • I had previously applied the " -std=c++11" fix to make modern C++ things like "unique_ptr" syntax work.
  • std::vector and other std template things are resolved without errors.
  • I have #include <array> and F3 successfully navigates to the array header file.

I tried the solution provided by schorsch312, and it worked except the steps presented are not exactly consistent with my Neon version of Eclipse (same version used by OP). Hence, I had to adjust the instructions slightly. Here is what worked for me:

  1. Select Project -> Properties -> C/C++ General -> C/C++ Paths and Symbols -> Symbols
  2. On that page under Languages, select GNU C++
  3. Add...
    • Name: __cplusplus
    • Value: 201103L
  4. Check: Add to all configurations
  5. Apply / OK.

Select Project -> C/C+ Index -> Rebuild -- if that operation did not automatically trigger.

Now, eclipse can resolve references to array properly. Note that this solution assumes you have previously resolved the general issue of getting c++11 syntax working.

1

The problem is that the symbol __cplusplus does not have the value 201103L.

To change this you need to

  • Edit Project->Preferences->C/C++ General/C/C+ General->Paths and Symbols->GNU C++->Symbols add define __cplusplus and set value to 201103L setzen.

  • Add under Window->Preferences->C/C++/Build/Settings/Discovery/CDT GCC Build-in Compiler Settings das Argument "-std=c++11" der Command Line hinzufügen

  • Activate under Project->Preferences->C/C++ General/C/C++ General/Path and Symbols->Providers for all entries the checkbox Use global provider shared between projects

schorsch312
  • 5,553
  • 5
  • 28
  • 57