Search code examples
objective-cmacoscocoadlopen

lib vs MacOSX bundle: how to get some information about the proc environment, e.g. how was it loaded


I'm hacking around a bit.

I have some ObjC code which defines a function with __attribute__((constructor)) void init. I link this statically to some MacOSX app. It is also linked statically to some other MacOSX bundle.

At some place, I load the MacOSX bundle binary directly via dlopen. First question: Is that a difference than to load it like [[NSBundle bundleWithPath:[NSString stringWithUTF8String:path]] load] or so?

In init, I would like to get some information about the process environment, e.g. how this code was loaded. E.g. the filename of the binary of the current process (which is in any case very likely a Cocoa app). And maybe more.


Solution

  • Some very helpful stuff:

    [[NSBundle mainBundle] executablePath]
    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];