Makefile vpath不适用于头文件 [英] Makefile vpath not working for header files

查看:180
本文介绍了Makefile vpath不适用于头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的Makefile中使用vpath,以避免为每个源文件添加目录名。

I am trying to use vpath in my Makefile to avoid prefixing every source file with directory name. But I can't get it to work properly.

Here's the Makefile:

c $ c> CC = gcc -Wall

vpath%.h包含
vpath%.c src

all:main.c Event.o Macros.h
$(CC)$& Event.o -o test / a.out

Event.o:Event.c Event.h Macros.h
$(CC)-c $& -o $ @

CC=gcc -Wall vpath %.h include vpath %.c src all: main.c Event.o Macros.h $(CC) $< Event.o -o test/a.out Event.o: Event.c Event.h Macros.h $(CC) -c $< -o $@

正确包含src 目录。即event.c文件由gcc找到。但是Event.h和Macros .h都不是。我在gcc中得到一个错误,说在编译Event.c时找不到这两个文件。

The src directory is being included correctly. i.e Event.c file is found by gcc. But both Event.h and Macros .h are not. I get an errors in gcc saying that both files were not found when compiling Event.c.

我试图将C文件中的#include指令更改为一个时间。

I tried changing the #include directive in my C file to each of these at a time.

#include "Event.h" /* doesnt work */
#include <Event.h> /* doesnt work */
#include "../include/Event.h" /* works */


b $ b

您能帮我解决这个问题吗?我真的想避免在每个源文件之前使用目录名,因为我的实际Makefile比这大。

Can you please help me with this problem ? I really want to avoid using directory names before every source file as my actual Makefile is bigger than this.

推荐答案

$ c> vpath 指令仅控制Make如何查找依赖关系;它不以任何方式影响GCC的工作原理。如果你在其他目录下有头文件,你明确需要告诉GCC -I

The vpath directive only controls how Make finds dependencies; it doesn't affect in any way how GCC works. If you have headers in some other directory, you explicitly need to tell GCC with -I:

INCLUDE := include

$(CC) -I$(INCLUDE) $c $< -o $@

这篇关于Makefile vpath不适用于头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆