i'm confused about the following include files(with GCC)
我对以下包含的文件(与GCC)感到困惑
i've A.c and B.c in folder AAA
我一个。c和B。在文件夹c AAA
and B.h in folder BBB
和B。BBB h在文件夹
in A.c:
交流:
#include <stdio.h>
#include "B.h"
main()
{
errPrint();
}
in B.c:
在公元前
#include <stdio.h>
#include "B.h"
void errPrint(void)
{
printf("err info\n");
}
in B.h:
在B.h:
#ifndef _B_H
#define _B_H
void errPrint(void);
#endif
now i run the command:
现在我运行命令:
#gcc -I /BBB A.c B.c -o exeobj
# gcc - i / BBB。c B。c - o exeobj
it's OK. but it seems a little boring that i have to use "-I" to specify header when in other folder. so i edit my "/etc/profile" file and added
没关系。但似乎有点无聊,我必须使用“-”来指定在其他文件夹中的头。因此我编辑我的“/etc/profile”文件并添加。
C_INCLUDE_PATH=/BBB
export C_INCLUDE_PATH
to specify the header folder, then
然后,指定标题文件夹。
echo $C_INCLUDE_PATH
it shows the right route. but when i compile:
它显示了正确的路线。但是当我编译:
#gcc -c A.c B.c
error shows:
错误显示:
error: B.h: No such file or directory
i don't know where went wrong, anybody have clues about it, any suggestions are weclome.
我不知道哪里出了问题,任何人都有线索,任何建议都可以。
note: i'm a newbie and can't use Makefile yet...
注意:我是新手,还不能使用Makefile…
1 个解决方案
#1
0
in A.c:
交流:
#include <stdio.h>
#include <B.h>
main()
{
errPrint();
}
in B.c:
在公元前
#include <stdio.h>
#include <B.h>
void errPrint(void)
{
printf("err info\n");
}
If want to use #include "file.h"
you gotta specified path example: "/BBB/B.h"
如果要使用#include“文件”。h"你必须指定路径示例"/BBB/B.h"
For more info you can read In the C standard section 6.10.2, paragraphs 2 to 4.
欲了解更多信息,请参阅C标准节6.10.2,第2至4段。
EDIT: After test. try it please.
编辑:在测试。请试一试。
echo -e "C_INCLUDE_PATH=/BBB\nexport C_INCLUDE_PATH" >> ~/.bash_profile
source ~/.bash_profile
and now
现在
gcc A.c B.c
Good Lucks :)
好菜:)
#1
0
in A.c:
交流:
#include <stdio.h>
#include <B.h>
main()
{
errPrint();
}
in B.c:
在公元前
#include <stdio.h>
#include <B.h>
void errPrint(void)
{
printf("err info\n");
}
If want to use #include "file.h"
you gotta specified path example: "/BBB/B.h"
如果要使用#include“文件”。h"你必须指定路径示例"/BBB/B.h"
For more info you can read In the C standard section 6.10.2, paragraphs 2 to 4.
欲了解更多信息,请参阅C标准节6.10.2,第2至4段。
EDIT: After test. try it please.
编辑:在测试。请试一试。
echo -e "C_INCLUDE_PATH=/BBB\nexport C_INCLUDE_PATH" >> ~/.bash_profile
source ~/.bash_profile
and now
现在
gcc A.c B.c
Good Lucks :)
好菜:)