2

I have the following code in eclipse: I'm running Indigo SR 2, 64bit with CDT Version: 8.0.2.201202111925 Build id: @build@ I have the Java SDK, Android SDK, and C++ CDT. I Believe the problem is only happening with c++ 11 functions: it seems Eclipse's internal code analyzer CODAN is not properly finding the libraries, even though the compiler is (i have the std=C++11 flag on my compilers).

I think this topic is related: http://www.eclipse.org/forums/index.php/t/490066/

#include <iostream>
#include <array>
using namespace std;

    int main(){
    cout << "test";

          array<int,5> myints;
          int x = 0;
          cout << "size of myints: " << myints.size() << std::endl;
          cout << "sizeof(myints): " << sizeof(myints) << std::endl;

          return 0;

    }

and I'm getting an error/ not compiling because I'm told:

Symbol 'array' could not be resolved

Why am I not compiling? I'm using eclipse indigo with the CDT and cygwin. I can provide more info as necessary.

UPDATE: I compile through eclipse (hammer button or right click project and click build) using Cygwin GCC and the Cygwin PE Parser.

Update 2: Running in indigo gives both an error in editor and a fail to compile, Kepler gives me the error, but seems to succeed running and compiling. Is there a way to make the error go away in kepler? Also, how would I get the actual command being passed to the compiler from within eclipse?

Update 3: More weirdness, after compiling in Kepler, it now compiles in indigo as well, though the errors persist in the text editor in both version.

1) Is there a way I can make these errors more accurate to the compile?

2) I can press f3 on the include and view it's source, so why can't eclipse seem to find the array symbol?

3) I'm also being told that the first std::endl is an Invalid overload of 'std::endl'

Update 4: I tried std::tr1::array<int, 3> arr1 = {1, 2, 3}; and it's still telling me that array cannot be resolved. I've added -std=c++11 to my c/C++ Build -> Settings -> Cygwin C++ Compiler -> Miscellaneous -> Other flags. It now reads: -c -fmessage-length=0 -std=c++11 But I'm seeing no change at this point

Update: This question seems to be getting at the problem: Eclipse C/C++ Shows Errors but Compiles? However, I've added a link to the directory "D:/Wamp/cygwin64/lib/gcc/x86_64-pc-cygwin/4.8.2/include" and it hasn't changed anything...

Thanks!

Community
  • 1
  • 1
iceburg
  • 53
  • 2
  • 10
  • 1
    I guess C++11 array feature is not supported in by the compiler? how did you compile it? – taocp Mar 20 '14 at 02:11
  • Does the code fail to compile, or is it just Eclipse code analyzer showing errors? If it's the former, post the command line being passed to the compiler, and include what compiler and version you're using. – Praetorian Mar 20 '14 at 02:14
  • Could be that Indigo lacks the support. When I try this in Eclipse Kepler (although using MinGW and not Cygwin, not that it should matter) it works fine, and array resolves to a template for TR1 array. – jpw Mar 20 '14 at 02:15
  • See if you can force C++11 mode. For GCC it's the `-std=c++11` switch. It's often not the default, even for compilers that support it. Alternatively try `` instead, and if that works then you know C++11 is turned off. – Adam Mar 20 '14 at 02:40
  • Thanks @Adam, I tried `std::tr1::array arr1 = {1, 2, 3};` and it's still telling me that array cannot be resolved. I've added `-std=c++11` to my c/C++ Build -> Settings -> Cygwin C++ Compiler -> Miscellaneous -> Other flags. It now reads: `-c -fmessage-length=0 -std=c++11` But I'm seeing no change at this point. – iceburg Mar 20 '14 at 02:45

3 Answers3

1

I think I got this resolved by changing the following settings: Project->Properties->C/C++ General/Preprocessor Include Paths, Macros Etc. -> Providers (tab)

Then "CDT GCC Built-in Compiler Settings" -> click the link "Workspace Settings" "CDT GCC Built-in Compiler Settings" (again), under "Command to get compiler specs:" add: "-std=c++11"

It took a refresh and then the little red squiggles went away.

This was the source: http://www.eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018

I also tried following this: http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds but it didn't exactly work. Probably because I'm on Ubuntu.

Peter
  • 375
  • 1
  • 4
  • 16
  • Much thanks,@Peter! I'm using Indigo Service Release 2 Build id: 20120216-1857, 64 bit and I'm not seeing a Preprocessor option under Project>Properties>C/C++ General. Is there another place I should look? I'll try Kepler and keep looking until I hear back from you, as well as read through these links. Thank you! – iceburg Mar 20 '14 at 20:08
  • Update: Found it on Kepler. It was `${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"` and now is: `${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}" -std=c++11` I also tried adding "-std=c++11" (with the qoutes). Closeing and reopening the project showed no squigglies, but making a change to the code (updating a string) made the squigglies come back. =/ I'm sure this is in the right direction though... – iceburg Mar 20 '14 at 20:18
  • Using the weather example from scrupulousabstractions, I have a ton of errors (including std::cout not being resolved)... =/ – iceburg Mar 20 '14 at 20:56
  • Oh no! Sorry for pointing you to that, then. IIRC the instructions on there do have you remove a bunch of things that I added back. Specifically where it says to deselect a bunch of things on the providers tab--I ended up putting those back. – Peter Mar 20 '14 at 21:34
  • Oh, I simply mean that the weather example is also giving me editor errors, I'm certainly no worse off, just noticing that other includes seem to be compiling but not working in the editor. :) I've also updated the question with a link to a similiar question. This seems to be an issue with CODAN (the CDT internal indexer)... – iceburg Mar 20 '14 at 21:52
  • From my quick experimentation with netbeans, it seems the problem persists across api. Perhaps its a problem with the libraries some how? – iceburg Mar 20 '14 at 22:44
  • OK. Well, I'm certainly out of my league on this thing. All I know is that adding -std=c++11 to seemed to do the trick for me. I did add it before "${INPUTS}", in case that makes any difference. – Peter Mar 21 '14 at 01:10
  • I tried placing it before and it didn't work either. Thank you though. Even having suggestions to try was really encouraging. :) It seems to only happen with c++ 11 functions, so maybe an update will make it work... – iceburg Mar 21 '14 at 02:31
0

I had added "-std=c++11" to the end of the "Command to get compiler specs" within Workspace Settings > C/C++ > Build > Settings > Discovery (tab) > CDT GCC Built-in Compiler Settings"...

And I had set my project so "Enable project specific settings" was disabled, under Properties > C/C++ General.

But still I got C++11 related CODAN errors.

I just discovered that unchecking "Enable project specific settings" does not guarantee the project will use the Discovery settings from the workspace. You still have to go in your project to Properties > C/C++ General > Preprocessor Include Paths, Macros etc. > Providers (tab) > CDT GCC Built-in Compiler Settings ... and make sure the option "Use global provider shared between projects" is checked (which it is not by default on my system, running Eclipse IDE for C/C++ version 2019-09 R). With this option checked "CDT GCC Built-in Compiler Settings" now shows [ Shared ] next to it.

There are a few other discovery providers where you need to set a similar option to ensure [ Shared ] shows up in the list (if you are trying to have your workspace settings apply). The "CDT User Settings Entries" I leave as project-specific, but the others I share in order to use the workspace-level settings.

CODAN is now working properly, and I no longer need to manually "freshen" the indexes and/or add #include statements to nudge CODAN along.

MikeOnline
  • 994
  • 11
  • 18
0

C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Dialect -> Language standart -> select which one you want to use.

You don't need to add "-std=c++11" anywhere else

ytukel
  • 53
  • 6