使用 C_INCLUDE_PATH 的 gcc 标头搜索路径

问题描述 投票:0回答:1

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

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

文件夹BBB中的B.h

在交流电中:

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

main()
{
    errPrint();
}

在BC:

#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...

c gcc header include-path user-profile
1个回答
0
投票

在交流电中:

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

main()
{
    errPrint();
}

在BC:

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

如果想使用

#include "file.h"
,你必须指定路径示例:
"/BBB/B.h"

有关更多信息,您可以阅读C 标准第 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

祝你好运:)

© www.soinside.com 2019 - 2024. All rights reserved.