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

混江龙づ霸主 提交于 2019-12-13 07:09:52

问题


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:


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)


来源:https://stackoverflow.com/questions/9865965/how-to-include-h-files-in-c-files-if-i-use-makefile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!