I want to open a number of files (log4cxx configs, other logs etc) relative to binary's location.
Unfortunately, both getwd()
and getcwd()
are giving me the directory, from which I try to run binary at known path, instead of giving me the path where the binary is located (and where the data is).
How to get the app's path to use it with chdir()
? Any methods besides argv[0]
and without trying to parse /proc/$PID/ (that's not portable enough)?
This is exactly the kind of thing autoconf lives for, and supporting those standard directories is pretty much mandatory if you ever want anyone other than the programmers who wrote your software to use it. Once set up properly, to debug out of your home directory all you have to do is pass a different --prefix=
value to configure
.