Eclipse: Compiles, but CODAN (internal code analyzer) gives errors for functions from C++ 11 <includes>

烈酒焚心 提交于 2020-01-24 13:58:09

问题


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!


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/22522048/eclipse-compiles-but-codan-internal-code-analyzer-gives-errors-for-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!