如何找出从哪里加载程序数据?
我有一个用 C++ 编写的项目(在 glibmm 的帮助下),并且我正在使用自动工具来管理它。 我要问的问题是“我到底如何确定从哪里加载东西?”。 虽然我可以在自动工具上找到所有我想要的指南,但没有一个能回答这个问题。
例如,地图放在 $DATADIR/maps
中(通常是 /usr/[local/]share/myprogram/maps
。Autotools 做了正确的事情并将它们放在那里,但是我如何知道它是将它们放在那里还是 $HOME/myprogram/maps
并适当地加载它们(理想情况下它会首先搜索 $PWD
,但这很容易)。
I've got a project written in C++ (with glibmm helping), and I'm using autotools to manage it. The question I have to ask is "HOW ON EARTH DO I FIGURE OUT WHERE TO LOAD STUFF FROM?". While I can find all the guides I want to on autotools, none answer this question.
For example, maps go in $DATADIR/maps
(usually /usr/[local/]share/myprogram/maps
. Autotools does the right thing and puts them there, but how do I know whether it put them there or $HOME/myprogram/maps
and load them appropriately (idealy it'd would search $PWD
first, but that's easy).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将字符串构建到您可能想要查看的各种自动配置位置的可执行文件中。这或多或少是 GCC 等程序所做的事情。
例如,我机器上的 GCC 4.3.3 是在 /work5/tmp 下编译的,并配置为安装在 /usr/gcc/v4.3.3 中,并且它包含(以及许多其他字符串)字符串:
一条注释说:“这就是我的意思正在想办法怎么办?”
方法有很多种。 部分答案是知道您需要哪些名称。 如果查看自动配置输出,会发现 makefile 中有诸如 prefixdir 和 pkglibdir 之类的名称。 您可以将它们添加到 C 编译器行:
并将 DFLAG1 添加到 CFLAGS。 重复令人作呕...
程序内的代码可以执行以下操作:
一种更简洁的方法是修改生成的 config.h 文件和配置代码,以便在配置中定义您感兴趣的目录。 h 文件中,而不是 makefile 中。
You can build the strings into your executable for the various autoconfigured locations that you might want to look in. This is more or less what programs such as GCC do.
For example, GCC 4.3.3 on my machine was compiled under /work5/tmp and configured for installation in /usr/gcc/v4.3.3, and it contains (amongst many others) the strings:
A comment says: "That's what I'm trying to figure out how to do?"
There are numerous ways. Part of the answer is knowing which names you need. If you look at the autoconfigure output, there are names such as prefixdir and pkglibdir in the makefile. You could add those to the C compiler lines:
and add DFLAG1 to your CFLAGS. Repeat ad nauseam...
The code inside your program can then do things like:
A cleaner way to do it is to modify the generated config.h file and the configure code so that the directories you are interested in are defined in the config.h file, rather than in the makefile.
乔纳森·莱弗勒(Jonathan Leffler)的回答很有帮助(他为我提供了足够的信息来获取源代码进化并找到我需要做的事情),但它并没有完全回答我的问题,所以我将在这里发布完整的解决方案:
在配置中。 ac(或configure.in,无论如何)我在末尾添加了以下行:
在 src/Makefile.am 中,添加了以下内容:
在实际的 C++ 代码中,使用了以下内容:
再次感谢乔纳森向我展示了哪里看看,但我想为后代发布完整的答案。
Jonathan Leffler answer was helpful (he provided enough info for me to apt-get source evolution and find what I needed to do), but it didn't entirely answer my question, so I'll post the complete solution here:
In configure.ac (or configure.in, whatever) I added the following lines at the end:
In src/Makefile.am, the following was added:
In the actual C++ code, the following was used:
Once again, thanks Jonathan for showing me where to look, but I wanted to post the complete answer for posterity.