使用C_INCLUDE_PATH使用gcc的标头搜索路径

时间:2013-03-24 17:24:47

标签: c gcc header include-path user-profile

我对以下包含文件(使用GCC)感到困惑

我在文件夹AAA中有A.c和B.c

文件夹BBB中的

和B.h

在A.c:

#include <stdio.h>
#include "B.h"

main()
{
    errPrint();
}

在B.c:

#include <stdio.h>
#include "B.h"
void errPrint(void)   
{
    printf("err info\n");
}

在B.h:

#ifndef _B_H
#define _B_H
void errPrint(void);
#endif

现在我运行命令:

#gcc -I /BBB A.c B.c -o exeobj

没关系。 但似乎有点无聊,我必须使用“-I”来指定标题 其他文件夹。 所以我编辑我的“/ etc / profile”文件并添加了

C_INCLUDE_PATH=/BBB  
export C_INCLUDE_PATH

指定标题文件夹,然后

echo $C_INCLUDE_PATH

它显示了正确的路线。 但是当我编译:

#gcc -c A.c B.c

错误显示:

error: B.h: No such file or directory

我不知道哪里出了问题,任何人都有关于它的线索,任何建议都是我们的。

注意:我是新手,还不能使用Makefile ......

1 个答案:

答案 0 :(得分:0)

在A.c:

#include <stdio.h>
#include <B.h>

main()
{
    errPrint();
}

在B.c:

#include <stdio.h>
#include <B.h>
void errPrint(void)   
{
    printf("err info\n");
}

如果要使用#include "file.h",您需要指定路径示例:"/BBB/B.h"

有关详情,请参阅In the C standard第6.10.2节第2至4段。

编辑:经过测试。试试吧。

echo -e "C_INCLUDE_PATH=/BBB\nexport C_INCLUDE_PATH" >> ~/.bash_profile

source ~/.bash_profile

现在

gcc A.c B.c
祝你好运:)