Eclipse 中新建C 或C ++到项目时,头文件报警,显示“Unresolved inclusion:<stdio.h>” 虽然不影响项目到编译和运行,确也无法查看头文件,让人感觉实在不爽。下面是在国外到网站上看到解决方案,自己整理了一下拿来分享一下。关于在Eclipse 下配置C /C ++ 开发环境这里不多说了。

在终端下查看C 库文件到路径:

$ echo "int main() { return 0; }" > a1.c

$ gcc -v a1.c

#include "..." 搜索从这里开始:
#include <...> 搜索从这里开始:

/usr/lib/gcc/i686-linux-gnu/4.6.1/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include

搜索列表结束。

……

查看C++ 库文件到搜索路径:

$ echo "int main() { return 0; }" > a1.cpp

$ g++ -v a1.cpp

#include "..." 搜索从这里开始:
#include <...> 搜索从这里开始:
 /usr/include/c++/4.6
 /usr/include/c++/4.6/i686-linux-gnu/.
 /usr/include/c++/4.6/backward
 /usr/lib/gcc/i686-linux-gnu/4.6.1/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
搜索列表结束。

在eclipse中菜单Window --> Preferences --> C/C++ --> Build --> Environment添加环境变量

C_INCLUDE_PATH =/usr/lib/gcc/i686-linux-gnu/4.6.1/include:/usr/local/include:/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed:/usr/include/i386-linux-gnu:/usr/include

CPLUS_INCLUDE_PATH =/usr/include/c++/4.6:/usr/include/c++/4.6/i686-linux-gnu/.:/usr/include/c++/4.6/backward:/usr/lib/gcc/i686-linux-gnu/4.6.1/include:/usr/local/include:/usr/lib/gcc/i686-linux-gnu/4.6.1/include-fixed:/usr/include/i386-linux-gnu:/usr/include

记得选中下面的Append variables to native environment.

添加完后重启Eclipse 新建项目即可。

05-27 20:01