Pregunta

I have a couple projects that depend on additional files, like images or config files.

When compiling and installing a programs like Okular with cmake, I can specify an installation directory and let make install install to that. Somehow, that program will figure out that all its dependencies are within that folder, not withing the main Linux file system.

So far, I had absolute paths, like /etc/config.ini. The problem is that I cannot test the program without it installing it to my system any more.

How can I do that easily in C++ and Python?

¿Fue útil?

Solución

C/C++/other languages built with cmake/autotools/...

The usual method is to have the build system either pass the specified installation directory to the compiler as a define flag (-DPREFIX=${CMAKE_INSTALL_PREFX}) or written in a configuration header (#define PREFIX @CMAKE_INSTALL_PREFIX@). This gets compiled in the code, constant values are thus used at runtime.

Note, that it is important to allow the prefix to be changed for the installation, i.e. install the files in different path from what is compiled in the sources. This is used when creating packages and various special cases when the files will eventually be linked or mounted into the location that was compiled in the code. Both cmake and autotools allow such overriding by default.

Python

Here the usual method is simply placing all your data in the directory where your modules are and search for them in sys.path.

Licenciado bajo: CC-BY-SA con atribución
scroll top