缘起
在使用Eclipse CDT(C/C++ Development Tooling)进行c/c++编程时,在使用c++11的关键字,如auto等,会遇到ide提示
'auto' could not be resolved
但是,只要编译器支持,这样的编译运行也不会报错。 这时需要在eclipse中打开c++的较新标准的支持
在新建项目之前设置
打开 Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build-in Compiler Settings (最后一项按照自己的具体的编译器进行更改,比如修改CDT GCC Build-in Compiler Settings) 在标题为“Command to get compiler specs:”的框内添加
-std=c++11
在创建的新项目中设置
以这样的方式打开的项目: File -> New -> Project -> C/C++ -> C++ Project, 在选定项目上单击鼠标右键,打开 Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Dialect
然后执行以下至少一个步骤:
- 在标题 other dialect flags 的框中添加 -std=c++11
- 在C++标准支持的下拉菜单中选择 ISO C++11
在CMake项目中设置
- 在你的项目内部生成 eclipse project 文件
mkdir build
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ..
- 然后将生成的目录作为一个标准的eclipse项目导入进来
- 右键单击并打开 Properties -> C/C++ General -> Preprocessor Include Paths, Marcos etc. -> Providers
- 启用 CDT GCC Build-in Compiler Settings,然后将其上移至Contributed PathEntry Containers的上方(这很重要)
- 重新编译项目,重新生成 Project ->C/C++ Index 接着重启Eclipse
|