c++ - Eclipse CDT for Linux -
i have written program using c++11 features.
/* * test.cpp * * created on: 05-jul-2015 * author: avirup */ #include<vector> #include<iterator> #include<iostream> using namespace std; int main() { vector<int> v; v.push_back(5); v.push_back(7); for(auto i=v.begin();i!=v.end();i++) { cout<<*i<<endl; } for(auto i=v.cbegin();i!=v.cend();++i) { cout<<*i<<endl; } } the program compiling correctly , showing results editor showing red lines below valid functions cbegin() , cend() constant reference iterators. annoying. how rid of this?
just completeness since has no answer , give explanation.
to achieve compiling c++ 11 (or version) , eclipse supporting need 2 things.
first compiler flag needs set -std=c++11 or -std=c++0x appended when calling g++ or whatever used.
- open properties properties project. select , right click ↦ properties (or alt+enter windows users)
- go
c/c++ build↦settings, maybe select preferred configuration, ↦gcc c++ compiler(or other compiler use) ↦dialect. - select combo or write flag
other dialectflags if not present in combo (like-std=gnu++14or-std=c++1z).

cdt call compiler -std=c++0x when compiling. part cdt supports c++11 , not show errors missing types , such. libstdc++ contains lines like
#if __cplusplus < 201103l # include <bits/c++0x_warning.h> #else // c++0x that causes errors , actual type declarations/definitions greyed out if view them in c/c++ editor. __cplusplus needs set correctly #define __cplusplus 201103l parsed , indexed cdt. done via project settings or can done whole workspace.
- go again project settings.
c/c++ general↦preprocessor include paths, macros etc., maybe select preferred configuration, ↦ tabproviders.- select entry compiler (for me it’s
cdt gcc built-in compiler settings mingw. - add
-std=c++11or-std=c++0xcommand compiler specstextfield @ location. - optional: select
allocate console in console view, hit apply. should see#define __cplusplus 201103lin console.

to set whole workspace check use global provider shared between projects , click on workspace settings identical dialog opens.
i’m writing plug-in extends new c/c++ project wizard 1 can select c++ version project sets compiler flag correctly , above setting indexer , other stuff. dunno if ever integrated cdt or needs installed via plug-in. sure in https://www.cevelop.com in few months.
Comments
Post a Comment