如果使用makefile,如何在.c文件中包括.h文件 [英] how to include .h files in .c files if I use makefile

查看:445
本文介绍了如果使用makefile,如何在.c文件中包括.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)

如果我想在.c文件中包含.h文件,是否需要在.c文件中写入"#include"../include-private/XX.h""??? 如果我只写.c"include" XX.h"该怎么办?

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" "?

因为我需要使用其他人提供的包含文件夹"中的.h文件,我如何在.c文件中写入以包含这些.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??

我的makefile在下面:

my makefile is below:

如何将.h文档包含在makefile中

谢谢您的帮助!

推荐答案

取决于编译器,但是通常,您需要添加以下行:

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

 CFLAGS += -I../include-private

CFLAGS是一个变量,用于添加C编译器的命令行选项("C"标志).对于C ++,您需要使用CXXFLAGS.如果我在同一项目中使用C和C ++,通常会创建一个名为INCLUDES的变量,并像这样使用它:

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)

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

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