Linux程序中的路径管理
我有一个 Linux 编程新手问题。假设我有一个使用 Autotools 进行编译和部署的项目,并且我有要安装在 /var/something
或 /usr/share/something
等位置的数据文件code> 等,但在 Autoconf 中,我可以更改这些安装路径。程序应该如何找到这些文件?它如何知道它们实际安装在哪里(如果在任何地方,因为即使没有安装程序也应该工作,但从构建的位置运行)?
I have a newbie Linux programming question. Suppose I have a project that uses Autotools for compiling and deployment, and I have data files that are to be installed in a location like /var/something
or /usr/share/something
etc., but in Autoconf, I can change these installation paths. How should the program find these files? How does it know where they are actually installed (if anywhere, since the program should work even if not installed, but run from where it was built)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,如果您的程序依赖于存储在可由构建系统调整的特定位置的文件,则应将此路径作为编译器定义传递,并在程序中在需要时使用该定义。
Typically if your program depends on files being stored in a certain location that is tunable by the build system, you should pass this path as a compiler definition and in your program use that definition where you need it.