Finding current executable's path without /proc/self/exe

前端 未结 13 1110
有刺的猬
有刺的猬 2020-11-22 01:06

It seems to me that Linux has it easy with /proc/self/exe. But I\'d like to know if there is a convenient way to find the current application\'s directory in C/C++ with cros

13条回答
  •  猫巷女王i
    2020-11-22 01:30

    If you ever had to support, say, Mac OS X, which doesn't have /proc/, what would you have done? Use #ifdefs to isolate the platform-specific code (NSBundle, for example)?

    Yes isolating platform specific code with #ifdefs is the conventional way this is done.

    Another approach would be to have a have clean #ifdef-less header wich contains function declarations and put the implementations in platform specific source files. For example, check out how Poco C++ library does something similar for their Environment class.

提交回复
热议问题