[英]How to set a define through “./configure” with Autoconf
I have one project that can generate two diferent applications based on one define.我有一个项目可以根据一个定义生成两个不同的应用程序。
libfoo_la_CXXFLAGS = -DMYDEFINE
I have to modify the Makefile.am to set this define, so it is not automatic.我必须修改 Makefile.am 来设置这个定义,所以它不是自动的。
Can I set this define somehow through the configure command?我可以通过配置命令以某种方式设置这个定义吗? Is there any other way to set one define using autotools?
有没有其他方法可以使用 autotools 设置一个定义?
You have to edit the file configure.ac
, and before AC_OUTPUT
(which is the last thing in the file) add a call to AC_DEFINE
.您必须编辑文件
configure.ac
,并在AC_OUTPUT
(这是文件中的最后一件事)之前添加对AC_DEFINE
。
In a simple case like yours, it should be enough with:在像你这样的简单情况下,它应该足够了:
AC_DEFINE(MYDEFINE)
If you want to set a value, you use:如果要设置值,请使用:
AC_DEFINE(MYDEFINE, 123)
This last will add -DMYDEFINE=123
to the flags ( DEFS =
in Makefile), and #define MYDEFINE 123
in the generated autoconf header if you use that.最后一个会将
-DMYDEFINE=123
添加到标志(在 Makefile 中为DEFS =
),如果您使用它,则在生成的 autoconf 标头中添加#define MYDEFINE 123
。
I recommend you read the documentation from the beginning, and work through their examples and tutorials.我建议您从头开始阅读文档,并通过他们的示例和教程进行学习。 Also check other projects' configure files to see how they use different features.
还要检查其他项目的配置文件以了解它们如何使用不同的功能。
Edit: If you want to pass flags on the command line to the make
command, then you do something like this:编辑:如果要将命令行上的标志传递给
make
命令,则执行以下操作:
libfoo_la_CXXFLAGS = $(MYFLAGS)
Then you call make
like this:然后你像这样调用
make
:
$ make MYFLAGS="-DMYDEFINE"
If you don't set MYFLAGS
on the command line, it will be undefined and empty in the makefile.如果没有在命令行中设置
MYFLAGS
,它将在 makefile 中未定义且为空。
You can also set target-specific CPPFLAGS
in Makefile.am
, in which case the source files will be recompiled, once for each set of flags:您还可以在
Makefile.am
设置特定于目标的CPPFLAGS
,在这种情况下,源文件将被重新编译,每组标志一次:
lib_LTLIBRARIES = libfoo.la libbar.la
libfoo_la_SOURCES = foo.c
libfoo_la_CPPFLAGS = -DFOO
libbar_la_SOURCES = foo.c
libbar_la_CPPFLAGS = -DBAR
这些天自动标题要求
AC_DEFINE([MYDEFINE], [1], [Description here])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.