使用 autoconf AC_ARG_WITH 将变量传递到 C 程序中
我正在尝试获取在./configure调用到C代码上提供的值,以便可以打印它。它应该像./configure一样传递到配置中-Allow-text =“某些文本”
我到目前为止的内容:
AC_PREREQ([2.69])
AC_INIT([proj], [0.0.1], [])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AM_PROG_CC_C_O
txt=something
AC_ARG_WITH([text],
AS_HELP_STRING([A string to be printed]),
[txt="$withval"], [])
AC_DEFINE([TEXT])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
但是我不知道下一步该怎么做以及如何访问main.c中的变量。
I'm trying to get a value provided on the ./configure invocation through to C code so it can be printed. It should be passed into configure like ./configure --allow-text="Some text"
What I have so far:
AC_PREREQ([2.69])
AC_INIT([proj], [0.0.1], [])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AM_PROG_CC_C_O
txt=something
AC_ARG_WITH([text],
AS_HELP_STRING([A string to be printed]),
[txt="$withval"], [])
AC_DEFINE([TEXT])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
But I don't know what to do next and how to access the variable in main.c.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AC_DEFINE_UNQUOTED
宏可用于扩展 shell 变量,例如:$txt
shell 变量的值将被放置在TEXT
宏中在AC_CONFIG_HEADERS([config.h])
命名的 config.h 文件中,例如:The
AC_DEFINE_UNQUOTED
macro can be used to expand shell variables, for example:The value of the
$txt
shell variable will be placed in theTEXT
macro in the config.h file named byAC_CONFIG_HEADERS([config.h])
, for example: