In my GNU/Linux environment, my software would have all of its graphical resources installed under /usr/share/pixmaps. In Wintendo everything would go into C:\Program files\myappname. In a different OS, somewhere else.
What are the most common ways, conventions, good practices so I can abstract my way to refer to the files I open in my code in a paths/installation/build independant way? Basically a portable way to refer to resources paths.
Create a preprocessor
ifelsechain of OS defines that#definesa function name mapped to a real function call that retrieves the correct path:This way you only call one function, and depending on your build target the correct function is called with no change in code.
Hard-coding the paths is generally not a good idea and is used here for illustration purposes only. You should probably set up a configuration file or similar to allow for individual systems to have separate install paths and still be able to find the resources.