c++11 code generates semantic errors in Eclipse, can't change build settings

房东的猫 提交于 2019-12-05 06:27:13

问题


I'm having trouble with c++11 code in Eclipse CDT. The code compiles fine, but in the editor I see that all references to c++11 standard library (such as std::shared_ptr and std::chrono::milliseconds) are flagged as errors by the discovery service / indexer, which prevents the program from being run. The include files are found, but I think the proper flags and macros aren't getting propagated through to CDT's internal checks, so none of the types or main content of the headers are defined. I also can't seem to change the appropriate settings in the project properties.

I've browsed other posts describing similar issues and possible fixes, such as:

  • Disable Eclipse's error discovery. (Codan false positives)
  • Eclipse compiles successfully but still gives semantic errors
  • c++0x compiles but eclipse editor errors even with -gnu++0x discovery
  • Eclipse CDT C++11/C++0x support

Some solutions mask the problem by disabling the indexer, or by disabling specific errors/warnings, but this is not desirable as I do want to see true errors when they occur.

Other (and probably more correct) solutions describe how to pass through appropriate macros (e.g,. __GXX_EXPERIMENTAL_CXX0X__) and build flags (e.g., -std=c++11), but here's what I think is the main issue: I can't change these settings in the IDE. In "Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc", the Entries and Providers tabs are grayed out / disabled. Similarly, in "Project -> Properties -> C/C++ Build -> Settings", there are no tabs for Tool Settings or Discovery as mentioned in some of the other posts.

Some particulars: I'm using Kepler build 20140224-0627 on Ubuntu 13.10 x64. The code I'm trying to work with is for Android NDK (latest version, r9d), and I have Google's NDK plugin installed. Compiler is gcc 4.8, and using gnustl_static runtime library. Perhaps using the NDK toolchain/plugin disables the settings that I need to modify?

Any help is greatly appreciated.


回答1:


First, make sure that your project compiles correctly.

After that, go to C/C++ Build->Tool Chain Editor and choose Current toolchain: Linux GCC (you may need to switch off Display compatible toolchains only). Make sure that the Current builder is still Android Builder.

Now you have full access to C/C++ General->Paths and Symbols page, with h Includes and # Symbols tabs.

On these two tabs, I add manually

C:/Android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.6/include
C:/Android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include
C:/Android/android-ndk-r9d/sources/cxx-stl/gnu-libstdc++/4.6/include/backward

and

__GXX_EXPERIMENTAL_CXX0X__ = 1

Maybe you need to switch to C/C++ Perspective, right-click on the project and launch Index->Rebuild.




回答2:


I have two contributions here:

  1. Update Eclipse if you can. They fix things now and then :)
  2. Generate a parser log file.

The first is self-explanatory, but I came to find out that my Eclipse config didn't have update sites configured, so I had to do that detour.

The second is hidden in plain site in the Project menu. The Indexing menu in Mars (Project / C-C++ Index) has "Create Parser Log File". This command generates a log pertaining to how it goes when the indexer parses the file that is "current" in the editor (i.e. the one you can see the red squigglies on at the moment). Generate that log and it will be opened automatically in an editor tab. If the indexer has a bug, it might report something interesting in this log. In my case it showed some headers such as <memory> were not parsed. That was certainly how it was acting, too. That was reported down at the bottom of the log, below all the info about what was successfully parsed. That enabled me to focus my investigation on a bug hunt rather than a configuration error or database corruption. Fortunately the bug that afflicted me was fixed in a newer version of Mars.



来源:https://stackoverflow.com/questions/22643664/c11-code-generates-semantic-errors-in-eclipse-cant-change-build-settings

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