通过 config.h 可移植地访问 sysconfdir
我希望我的应用程序能够便携式访问 make install
期间安装的配置文件 (dist_sysconf_DATA)。是否可以通过 config.h 访问 $(sysconfdir)
?
I'd like my application to have portable access to the configuration files installed during make install
(dist_sysconf_DATA). Is it possible to access $(sysconfdir)
via config.h?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,但你不应该根据官方的声音这样做(例如,我现在不会搜索手册),以便继续支持针对要构建的特定对象覆盖它。
因此,一个人应该做什么:
It is, but you should not do this according to official voices (as in, I am not gonna search the manual for it now) so as to continue supporting overriding it for specific objects to be built.
Hence, what one is supposed to do:
如果您使用 autoheader,将其添加到 configure.ac 将在 config.h 中输出 SYSCONFDIR 宏,并且它将使用值 $(sysconfdir) 或 ${prefix}/etc 进行定义。
但我强烈建议不要这样做,而是坚持使用 -DSYSCONFDIR 标志。它的代码较少,因此不太容易出现问题。在configure.ac 中使用我提到的条件可能无法移植,或者需要考虑可能遇到的每种情况。使用 -DSYSCONFDIR 是最好的选择。有时候,外表并不重要。
If you're using autoheader, adding this to your configure.ac will output a SYSCONFDIR macro in your config.h, and it will be defined with the value $(sysconfdir) or ${prefix}/etc.
But I would strongly recommend against doing that, and instead, stick with using the -DSYSCONFDIR flag. It's less code and therefore less prone to something going wrong. Using a condition in configure.ac such I mentioned may not be portable or take into account every case that might be encountered. Using -DSYSCONFDIR is the best option. Sometimes appearance just doesn't matter.
我认为最常见的做法(这就是我所做的)
在
Makefile.am
中添加以下内容AM_CPPFLAGS = -DSYSCONFIR='"$(sysconfdir)"'
现在您可以在源代码中访问
SYSCONFDIR
What I believe is most commonly done (and this is what I do)
Add the following in your
Makefile.am
AM_CPPFLAGS = -DSYSCONFIR='"$(sysconfdir)"'
And now you can access
SYSCONFDIR
in source