如何在使用#include<>?时修改.h文件的路径

时间:2011-11-08 12:34:21

标签: c gcc

当我们使用#include< stdio.h>在linux平台上,编译器会在/ usr / include中搜索stdio.h。如何更改使用#include<&gt ;?的路径 谢谢。

我之所以问这个问题:当我使用C标准函数isdigit()时,如果“#include< ctype.h>”未添加,程序生成警告但没有错误。但是如果“#include< ctype.h>”添加后,链接时会产生错误。(我的编译器不是标准的gcc。)

我想知道为什么?

2 个答案:

答案 0 :(得分:5)

 -I dir
     Add the directory dir to the list of directories to be
     searched for header files.  Directories named by -I are
     searched before the standard system include directories.

答案 1 :(得分:1)

有两种不同的方式:

  1. 在Makefile中使用-Idir或作为gcc的参数。

  2. 创建环境变量C_INCLUDE_PATH(对于C头文件)或CPLUS_INCLUDE_PATH(对于C ++头文件)。

相关问题