在 Makefile 中添加标头目录
您好,我想问您,如果有人知道如何在 Makefile 中添加头文件的目录以避免错误 *.h not found,我已经尝试过此选项但不起作用:
INC_PATH := -I /directory/to/add
Hello I would like to ask you, If someone knows how can I add a directory for the header files in the Makefile to avoid the error *.h not found, I have tried this option but does not work:
INC_PATH := -I /directory/to/add
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少对于 GNU make,请尝试隐式变量
CFLAGS
,如:At least for GNU make, try the implicit variable
CFLAGS
, as in:尽管目标最终是影响 CFLAGS 的值(如 @unwind 所建议的),但简单地设置 CFLAGS 的值通常不是一个好主意,因为它通常是由许多部分构建的。 您必须了解 makefile 的结构以及所使用的宏集。
[已添加:
Eduardo 询问:您可以发布宏来执行相同的操作吗?
是的,但它们是否有用取决于您的 makefile 的结构。 这是我的一个 makefile 中的一个中等复杂的示例。
这是我的一个名为
sqlcmd
的程序的 makefile(这个名称比 Microsoft 创建同名命令早了十年多)。 我假设 make 程序有一个将 C 代码编译为对象的规则,例如:并且从宏 OBJECTS 中列出的一组对象文件链接程序的规则如下所示:
如您所见,有单独可设置的 ESQLC_VERSION 宏(正在使用的 Informix ESQL/C 版本,默认情况下通过运行脚本
esqlcver
派生),然后是通过 INC1 到 INC5 和 INCFLAGS 的包含目录(可以有其中很多,具体取决于平台),以及优化器标志(OFLAGS)、额外标志(CFLAGS)、用户定义标志(UFLAGS - 我在大多数 makefile 中使用的习惯用法;它允许用户将 UFLAGS 设置为make
命令行并向构建添加额外的标志),以及一堆与库相关的宏。 这就是我的开发 makefile 能够轻松调整到我的开发平台(可以是 Linux、Solaris 或 MacOS X)所需的。对于程序的使用者,有一个由以下命令生成的configure
脚本autoconf
,因此他们不必担心这些位是否正确。 然而,它与该代码(包括 UFLAGS 选项)有很强的遗传相似性。请注意,许多 makefile 构建系统都有一个与此有点相似的设置 CFLAGS 的机制 - 并且简单地分配给 CFLAGS 会取消系统所做的良好工作。 但您必须了解您的 makefile 才能合理地修改它。
]
Although the goal is ultimately to affect the value of CFLAGS (as suggested by @unwind), it is often not a good idea to simply set the value of CFLAGS as it is often built out of many pieces. You have to understand the structure of the makefile, and the set of macros used.
[Added:
Eduardo asked: Can you post macros to do the same?
Yes, but whether they are helpful depends on how your makefiles are structured. Here's a moderately complex example from one of my makefiles.
This a makefile for a program of mine called
sqlcmd
(a name chosen a decade and more before Microsoft created a command of the same name). I assume that themake
program has a rule for compiling C code to object like:and that the rule for linking a program from a set of object files listed in the macro OBJECTS looks like:
As you can see, there are separately settable macros for the ESQLC_VERSION (the version of Informix ESQL/C in use, derived by default by runing a script
esqlcver
), then the include directories via INC1 to INC5 and INCFLAGS (there can be quite a lot of these, depending on platform), and optimizer flags (OFLAGS), extra flags (CFLAGS), user-defined flags (UFLAGS - an idiom I use in most of my makefiles; it allows the user to set UFLAGS on themake
command line and add an extra flag to the build), and a bunch of library-related macros. This is what it takes for my development makefile to be tunable with minimal fuss to my development platform, which can be Linux, Solaris or MacOS X. For consumers of the program, there is aconfigure
script generated byautoconf
, so they don't have to worry about getting those bits right. However, that has a strong genetic resemblance to this code, including the UFLAGS option.Note that many systems for makefile building have a mechanism for setting CFLAGS faintly similar to this - and simply assigning to CFLAGS undoes the good work done by the system. But you have to understand your makefile to be able to modify it sanely.
]