I am working on a C program that has a plugin architecture. We build and package both
Some plugins have additional non-binary resources, such as image files, or script files that only apply to that plugin. Those additional resources are in the put in the same directory as the plugin's
.so file. So the plugins need to know where they are located on disk, and in their same directory, be able to open their associated files.
Is there a standard, or at least more-or-less idiomatic, way of doing this?
Note that I am wary of hardcoding paths such as
/usr/lib/<foo>/plugins, especially since some distros like to use
Additionally, during development, the program (and/or plugins) are not installed in standard locations. They are executed out of a source code subdirectory in the user's home folder, and the plugin folders are in a slightly different relative location from the binary under development in these cases.
Edit: For a concrete example, the source tree for project
foo has a
plugins directory. Some standard plugins that are shipped with with
foo are maintained in the
plugins directory. One of the plugins,
pyconsole, relies on
foo_pycon.py, which is also in
During development, I might have several copies of the repo in my home directory, for different work on different branches. One working copy might be in
I invoke that locally-built instance of
foo locates all the plugins in a relative subdirectory, including
Is there a standard or idiomatic way for this particular instance of
pyconsole.so to know where it is located, so it can open and use its own
Note that when installed via packages, the relative paths are/might be different. Where as
/usr/bin/foo is the location of the installed binary, we install our plugins under