gpt4 book ai didi

Autoconf:如何将安装路径放入 config.h

转载 作者:行者123 更新时间:2023-12-01 16:23:49 25 4
gpt4 key购买 nike

我的程序需要在运行时加载一些文件,这些文件将被安装到提供给 ./configure --datadir=/somewhere 的任何文件夹中。

由于我的程序需要在运行时知道此文件夹的位置,因此我需要在某处#define 一个符号,以便 C 代码可以将路径作为字符串访问。

我目前通过修改编译器标志来做到这一点:

AM_CPPFLAGS = -DDATA_PATH=\"$(pkgdatadir)\"

但是,由于配置脚本已经生成了一个 config.h 文件,其中包含许多其他内容,因此我希望该符号出现在其中。

那可能吗?

最佳答案

您的回答是首选方式。 autoconf 手册解释了如何在“make install”时覆盖各种变量(例如,这对于打包非常有用)。这样做时它说(在“安装目录变量”部分中):

   A corollary is that you should not use these variables except in
makefiles. For instance, instead of trying to evaluate `datadir' in
`configure' and hard-coding it in makefiles using e.g.,
`AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])', you
should add `-DDATADIR='$(datadir)'' to your makefile's definition of
`CPPFLAGS' (`AM_CPPFLAGS' if you are also using Automake).

autotools 和一般的构建系统是一项复杂的业务,还没有人想出足够通用的漂亮整洁的做事方法,这意味着我们必须阅读像这样的部分并完全解决它。无论如何,你的直觉是正确的!

关于Autoconf:如何将安装路径放入 config.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5867136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com