Opened 6 years ago
Last modified 4 years ago
#12869 new Feature Requests
Getting the path of the current executable
| Reported by: | Owned by: | Beman Dawes | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | filesystem |
| Version: | Boost Development Trunk | Severity: | Optimization |
| Keywords: | Cc: |
Description
I couldn't find any other ticket relating to this issue, so I'm asking here. I think it would be really useful if Boost's FileSystem included a method for getting the path of the current executable in a cross-platform way. I needed this kind of functionality myself just now because I needed to find some files relative to the executable's dir, and I think that a lot of projects can benefit from it. As goes without saying, a solution for this problem in a mature well-tested library beats a quickfix in one of my own projects.
As has been noted in several threads on StackOverflow, using argv[0] to derive the current path has its flaws on many platforms (including mine). A more robust solution would be to use e.g. GetModuleFileName on Windows and /proc/self/exe/ on Linux. The code can I think be fairly easily copied from this StackOverflow answer, which, according to the author, has been tested on various platforms.
Regards, Sam

boost::dll::program_location() does exactly that?