how to include .h files in .c files if I use makef

2019-09-01 04:29发布

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)

if I want to include a .h file in my .c file, do I need to write in .c file " #include "../include-private/XX.h" "??? what if i just write in .c " include "XX.h" "?

Because I need to use the .h files in "include folder" which others supply for me, how could I write in my .c files to include these .h files??

my makefile is below:

how to include .h document in makefile

thank you for your help!!!

1条回答
老娘就宠你
2楼-- · 2019-09-01 04:54

Depends on the compiler, but typically, you'll want to add the following line:

 CFLAGS += -I../include-private

CFLAGS is a variable that make uses to add command-line options for the C compiler ("C" flags). For C++, you need to use CXXFLAGS. If I'm using C and C++ in the same project, I'll typically create a variable called INCLUDES, and use it like this:

 INCLUDES = -I../include-private

 CFLAGS += $(INCLUDES)
 CXXFLAGS += $(INCLUDES)
查看更多
登录 后发表回答