如何在makefile中包含.h文档

时间:2020-12-07 02:04:49

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)

My Makefile is below:

我的Makefile是如下:

####################################################
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) 
#################################################

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.

我的问题是,当我在终端上运行make时,它总是显示:***没有终止此类文件或目录编译。这似乎是。h文件。/SourceFile/include-private不包括在内。

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

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

I don't know where is wrong!

我不知道哪里出错了!

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 !

这是我第一次编写makefile。如果我的makefile中有错误,我希望您能指出来!

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

非常感谢您的帮助!

2 个解决方案

#1


0  

You can try to change $(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) -include $(include) $(SRCS)

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)

或$(CC) -c -I$(INC_DIR) $(SRCS)至$(CC) -c -I$(INC_DIR) -I$(包括)$(SRCS),其中include为./SourceFile/include-private(只有目录,没有.h文件)

Edit: 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.

编辑:通常不需要显式地包含.h文件,但这是第一个更改的作用。第二个更改不是显式地添加.h文件,而是向编译器提供另一个包含目录,以便搜索必要的.h文件。

Refer to GCC man file for more info.

有关更多信息,请参阅GCC man文件。

Regards

问候

#2


1  

You should have something like

你应该有类似的东西。

 CFLAGS = -Wall $(OPTIMFLAGS) $(INCLUDEFLAGS)
 INCLUDEFLAGS = -I $(INC_DIR) -I $(HEAD_PATH)
 OPTIMFLAGS = -g -O

You can use remake to debug your Makefile.

您可以使用“重做”来调试您的Makefile。

#1


0  

You can try to change $(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) -include $(include) $(SRCS)

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)

或$(CC) -c -I$(INC_DIR) $(SRCS)至$(CC) -c -I$(INC_DIR) -I$(包括)$(SRCS),其中include为./SourceFile/include-private(只有目录,没有.h文件)

Edit: 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.

编辑:通常不需要显式地包含.h文件,但这是第一个更改的作用。第二个更改不是显式地添加.h文件,而是向编译器提供另一个包含目录,以便搜索必要的.h文件。

Refer to GCC man file for more info.

有关更多信息,请参阅GCC man文件。

Regards

问候

#2


1  

You should have something like

你应该有类似的东西。

 CFLAGS = -Wall $(OPTIMFLAGS) $(INCLUDEFLAGS)
 INCLUDEFLAGS = -I $(INC_DIR) -I $(HEAD_PATH)
 OPTIMFLAGS = -g -O

You can use remake to debug your Makefile.

您可以使用“重做”来调试您的Makefile。