Search code examples
eclipsec++11android-ndksettingseclipse-cdt

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


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:

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.


Solution

  • 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.