我有一个简单的C文件,它可以编译。我现在正在尝试添加一个位于
的外部头文件../../myotherdir/tbt/include
这是我的C档案:
/* Hello World program */
#include<stdio.h>
#include "app.h"
main()
{
printf("Hello World");
}
这是我的makefile:
headerdir = ../../mytree2/tlk/include
hello: hello.c **app.h**
gcc -I$(headerdir) hello.c -o hello
如何在myotherdir / tbt / include中搜索标题文件并将其添加到我的项目中?
我按照Mureinik的建议更新了makefile。谢谢它的工作。现在我得到一个不同的错误,说明我没有制作app.h的规则。
我发现我的错误。我不应该添加app.h作为先决条件。我在上面用粗体突出显示了它。删除该行后,我得到了其他错误,但似乎我的make文件有效。谢谢Mureinik。
答案 0 :(得分:0)
gcc -o hello.o -I$(headerdir) hello.c
您不需要像这样指定VPATH。 你可以只更改headerdir以包含更多的头文件。例如
headerdir = ../../myotherdir/tbt/include ../path/to/next/header/dir ../etc/etc
答案 1 :(得分:0)
您可以使用-I
参数设置其他标题的位置:
hello: hello.c app.h
gcc -I${headerdir} hello.c -o hello