Makefile 我如何告诉gnu make头文件在哪里?
我有一个简单的C文件,可以编译。我现在正在尝试添加一个位于的外部头文件Makefile 我如何告诉gnu make头文件在哪里?,makefile,gnu-make,Makefile,Gnu Make,我有一个简单的C文件,可以编译。我现在正在尝试添加一个位于的外部头文件 ../../myotherdir/tbt/include 这是我的C文件: /* Hello World program */ #include<stdio.h> #include "app.h" main() { printf("Hello World"); } 如何让make在myotherdir/tbt/include中搜索HeaderFile并将其添加到我的项目中 我按照Mure
../../myotherdir/tbt/include
这是我的C文件:
/* Hello World program */
#include<stdio.h>
#include "app.h"
main()
{
printf("Hello World");
}
如何让make在myotherdir/tbt/include中搜索HeaderFile并将其添加到我的项目中
我按照Mureinik的建议更新了makefile。谢谢,成功了。现在我得到一个不同的错误,说明我没有一个规则来创建app.h
我想我发现了我的错误。我不应该添加app.h作为先决条件。我在上面用粗体突出显示了它。删除该行后,我出现了其他错误,但我的make文件似乎可以正常工作。谢谢你,穆雷尼克
gcc -o hello.o -I$(headerdir) hello.c
您不需要像那样指定VPATH。
您可以只更改headerdir以包含更多头文件。例如
headerdir = ../../myotherdir/tbt/include ../path/to/next/header/dir ../etc/etc
您不需要像那样指定VPATH。
您可以只更改headerdir以包含更多头文件。例如
headerdir = ../../myotherdir/tbt/include ../path/to/next/header/dir ../etc/etc
您可以使用
-I
参数设置附加标题的位置:
hello: hello.c app.h
gcc -I${headerdir} hello.c -o hello
您可以使用
-I
参数设置附加标题的位置:
hello: hello.c app.h
gcc -I${headerdir} hello.c -o hello
谢谢你的解决方案奏效了。现在它说我并没有一个构建app.h的规则。我不知道我也必须建立先决条件。你能建议一种处理方法吗?也许我需要创建一个像src这样的变量,并将我的规则修改为隐式的构建所有src文件的规则?这是因为您没有编译app.c。谢谢。你的解决方案奏效了。现在它说我并没有一个构建app.h的规则。我不知道我也必须建立先决条件。你能建议一种处理方法吗?也许我需要创建一个像src这样的变量,并将我的规则修改为隐式的构建所有src文件的规则?这是因为您没有编译app.c。