如何在makefile中包含.h文档 [英] how to include .h document in makefile

查看:481
本文介绍了如何在makefile中包含.h文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个大型项目编程,所以我与他人合作. 为了使目录易于管理,我的目录如下:

I am programming for a big project, so I cooperate with others. To make the directory easily managed, my directory is like below:

project:
--include (header files from others supplied for me)
--lib (libraries from others supplied for me)
--L3_CVS  (this folder include all my files)
   -- Makefile 
   -- sourceFile (all my source files here)
       -- include_private(all header files used only by myself)
       -- appl (all my C files here)

我的Makefile在下面:

My Makefile is below:

####################################################
CROSS_COMPILE=/home/powerpc-wrs-linux-gnu/x86-linux2/powerpc-wrs-linux-gnu-ppc_e500v2-glibc_cgl-

EXTRA_CFLAGS += -g

EXTRA_LDFLAGS +=

LIBSB =-Wl,--start-group -ldiag -ldiag_esw -lacl -ldiagcint -lcint -lsal_appl -lsal_appl_editline -lsal_appl_plat\

-lbcm -lbcm_esw -lbcm_common -lfirebolt -ltitan -ltrident -lhumv -lbradley -lherc -ldraco -lscorpion\

-ltriumph -ltrx -ltriumph2 -lenduro -lkatana -lflexctr -lptp -lsoc_esw -lsoc -lsoc_phy -lsoc_mcm\

-lsoccommon -lsoc_shared -lshared -lsal_core -lsal_core_plat -lcustomer -lsoc_nemo -lsoc_clsbuilder\

-lsoc_sal \

-lbcm_compat -lbcm_rpc -lcpudb  -ltrx  -lstktask -llubde -ldrivers -ldiscover -lcputrans \

-lrcu -lpthread -lrt -lm   -Wl,--end-group

LIBS = -ldiag -lrcu 

CC = $(CROSS_COMPILE)gcc

LD = $(CROSS_COMPILE)ld

AR = $(CROSS_COMPILE)ar

STRIP = $(CROSS_COMPILE)strip


SRC_PATH := ./SourceFile/appl

HEAD_PATH :=  ./SourceFile/include-private


INC_DIR  =  ../include

LIB_PATH =  ../lib


APP_NAME = L3appl

SRCS := $(wildcard $(SRC_PATH)/*.c)

export $(SRCS)

OBJS:= $(patsubst %.c,%.o,$(SRCS)) 

%.d: %.c

    @set -e; rm -f $@; \

    $(CC) -MM  $< > $@.$$$$; \

    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \

    rm -f $@.$$$$

sinclude $(SRCS:.c=.d)

INCLUDES = $(wildcard $(HEAD_PATH)/*.h)

$(APP_NAME):$(OBJS)

    $(CC)   -c -I$(INC_DIR) $(SRCS)

    $(CC)   -o  $(APP_NAME) $(OBJS) -L$(LIB_PATH) $(LIBSB)  -lpthread -lrt -lm


.PHONY:clean

clean: 

    rm   -f  $(OBJS) $(APP_NAME) 
#################################################

我的问题是,当我在终端中运行make时,它始终显示:***没有这样的文件或目录 编译终止.似乎不包含./SourceFile/include-private中的.h文件.

My problem is that when I run make in terminal, it always show : ***No such file or directory compilation terminated. which seems the .h files in ./SourceFile/include-private do not be included.

但是,实际上,我使用了".INCLUDES = $(通配符$(HEAD_PATH)/*.h)"包含这些.h文件.

But, in fact, I have use "INCLUDES = $(wildcard $(HEAD_PATH)/*.h)" include these .h files.

我不知道哪里错了!

这是我第一次编写makefile.因此,如果我的makefile文件中有错误,我希望您指出这些错误!

this is my first time to write makefile. So if there are mistakes in my makefile, I would appreciate that you would point them out !

非常感谢您的帮助!!!!!!!

thank you for your help very much!!!!!!!

推荐答案

您可以尝试更改$(CC) -c -I$(INC_DIR) $(SRCS) to $(CC) -c -I$(INC_DIR) -include $(INCLUDES) $(SRCS)

或$(CC)-c -I $(INC_DIR)$(SRCS)到$(CC)-c -I $(INC_DIR)-I $(INCLUDES)$(SRCS) 其中INCLUDES是./SourceFile/include-private(仅目录,没有.h文件)

or $(CC) -c -I$(INC_DIR) $(SRCS) to $(CC) -c -I$(INC_DIR) -I$(INCLUDES) $(SRCS) where INCLUDES is ./SourceFile/include-private (only the directory, no .h files)

通常不必显式包含.h文件,但这是第一个更改所做的.第二个更改不是显式添加.h文件,而是为编译器提供了另一个include目录,可以在其中搜索必要的.h文件.

Usually you don't have to explicitly include the .h files, but that's what the first change do. The second change does not add the .h files explicitely but provide the compiler another include directory where it could search for necessary .h files.

有关更多信息,请参考GCC手册文件.

Refer to GCC man file for more info.

致谢

这篇关于如何在makefile中包含.h文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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