【问题标题】:how to find the location of the executable in C in OS X [duplicate]如何在OS X中找到C中可执行文件的位置[重复]
【发布时间】:2013-09-08 19:16:24
【问题描述】:

与How do I find the location of the executable in C? 完全一样,但对于 Mac OS X。我知道 argv[0] 可能有效,但我想要一种以编程方式访问此信息(即函数调用)的方法,因为我正在编写的代码是其中的一部分一个无权访问 argv[0] 的库。

【问题讨论】:

  • 在 linux 上可以通过查看 /proc/self/exe 获得。也许 OS X 也有类似的东西?
  • @FatalError 它没有

标签: c++ c macos


【解决方案1】:

Mac OS X 实现的功能:

int _NSGetExecutablePath(char * buf, uint32_t * length);
int * _NSGetArgc(void);
char *** _NSGetArgv(void);

其中第一个可能是您想要的。不过,另外两个也很有趣!

【讨论】:

    猜你喜欢
    • 2010-10-30
    • 1970-01-01
    • 2011-06-27
    • 2015-11-17
    • 1970-01-01
    相关资源
    最近更新 更多