gcc: gcc include path gcc中include文件的搜索路径
2015-10-14 14:24
459 查看
we saw how to link to a program with functions in the C math library ‘libm.a’, using the short-cut option -lm and the header file ‘math.h’.
A common problem when compiling a program using library header files is the error:
This occurs if a header file is not present in the standard include file directories used by gcc. A similar problem can occur for libraries:
This happens if a library used for linking is not present in the standard library directories used by gcc.
By default, gcc searches the following directories for header files:
and the following directories for libraries:
The list of directories for header files is often referred to as the include path, and the list of directories for libraries as the library search path or link path.
The directories on these paths are searched in order, from first to last in the two lists above.(7) For example, a header file found in ‘/usr/local/include’ takes precedence over a file with the same name in ‘/usr/include’. Similarly, a library found in ‘/usr/local/lib’ takes precedence over a library with the same name in‘/usr/lib’.
When additional libraries are installed in other directories it is necessary to extend the search paths, in order for the libraries to be found. The compiler options-I and -L add new directories to the beginning of the include path and library search path respectively.
gcc搜索的路径取决于编译gcc时指定的路径。在编译gcc时做如下改变,会修改gcc引用路径
Change the StartFile Spec and Standard Include Dir so that GCC looks in /tools:
Now alter gcc's c preprocessor's default include search path to use /tools only:
此时编译出来的gcc工具其默认include搜索路径变为/tools/include了
A common problem when compiling a program using library header files is the error:
FILE.h: No such file or directory
This occurs if a header file is not present in the standard include file directories used by gcc. A similar problem can occur for libraries:
/usr/bin/ld: cannot find library
This happens if a library used for linking is not present in the standard library directories used by gcc.
By default, gcc searches the following directories for header files:
/usr/local/include/ /usr/include/
and the following directories for libraries:
/usr/local/lib/ /usr/lib/
The list of directories for header files is often referred to as the include path, and the list of directories for libraries as the library search path or link path.
The directories on these paths are searched in order, from first to last in the two lists above.(7) For example, a header file found in ‘/usr/local/include’ takes precedence over a file with the same name in ‘/usr/include’. Similarly, a library found in ‘/usr/local/lib’ takes precedence over a library with the same name in‘/usr/lib’.
When additional libraries are installed in other directories it is necessary to extend the search paths, in order for the libraries to be found. The compiler options-I and -L add new directories to the beginning of the include path and library search path respectively.
gcc搜索的路径取决于编译gcc时指定的路径。在编译gcc时做如下改变,会修改gcc引用路径
Change the StartFile Spec and Standard Include Dir so that GCC looks in /tools:
echo -en '#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR "/tools/include/"\n\n' >> gcc/config/linux.h echo -en '\n#undef STANDARD_STARTFILE_PREFIX_1\n#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"\n' >> gcc/config/linux.h echo -en '\n#undef STANDARD_STARTFILE_PREFIX_2\n#define STANDARD_STARTFILE_PREFIX_2 ""\n' >> gcc/config/linux.h
Now alter gcc's c preprocessor's default include search path to use /tools only:
cp -v gcc/Makefile.in{,.orig} sed -e "s@\(^CROSS_SYSTEM_HEADER_DIR =\).*@\1 /tools/include@g" \ gcc/Makefile.in.orig > gcc/Makefile.in
此时编译出来的gcc工具其默认include搜索路径变为/tools/include了
相关文章推荐
- android-----关于Menu
- Java连接MySQL数据库之mysql-connector-java
- 加载动态滚动条
- canvas保存为data:image扩展功能的实现
- Android 5.1 AppOps总结
- android-volley-manager
- 编辑推荐
- 音频界的瑞士军刀 --- SoX - Sound eXchange 国外开源音频处理软件介绍(一)
- 《深入理解java虚拟机》之类文件结构
- can not be used when making a shared object; recompile with -fPIC
- jquery中常用的一些方法
- 中国(北京)3d虚拟现实,工业仿真技术及产品展览情况
- 建模语言UML笔记整理之开篇概述
- unity 音乐播放器的制作
- 中国十大禁片电影,国外、世界十大禁片电影
- 如何解决在Azure上部署Sqlserver网络访问不了
- DESearchAlgorithm
- 使用Dom4j解析XML
- Android 判断是开发debug模式,还是发布release模式
- Javascript截图相关参考项目