本文介绍了Autoconf:如何将安装路径放入 config.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序需要在运行时加载一些文件,这些文件将被安装到 ./configure --datadir=/somewhere

My program needs to load some files at run time, which will be installed into whatever folder is given to ./configure --datadir=/somewhere

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

As my program needs to know where this folder is at run time, I need to #define a symbol somewhere so the C code can access the path as a string.

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

I am currently doing this by modifying the compiler flags:

AM_CPPFLAGS = -DDATA_PATH="$(pkgdatadir)"

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

However as the configure script already produces a config.h file with a bunch of other things in it, I would like to have the symbol appear in there instead.

这可能吗?

推荐答案

AC_DEFINE_UNQUOTED([DATA_PATH], ["$pkgdatadir"])

虽然修改编译器标志确实是更常用的方法.

Although modifying the compiler flags is really the more usual way to do it.

这篇关于Autoconf:如何将安装路径放入 config.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 23:56