tanlan
tanlan

Reputation: 13

Getting list of linked libraries form cocoa code

On my application starting I need to get list of libraries that are linked to it. Unfortunately, I could't find any example in cocoa how can I do it from code. Can anybody help me with this?

Upvotes: 0

Views: 422

Answers (1)

Catfish_Man
Catfish_Man

Reputation: 41801

So, there's probably a better way than this (and this is completely untested written-into-this-text-field code), but I think this would do the trick:

uint32_t imageCount = _dyld_image_count();
char **names = calloc(sizeof(char *), imageCount);
int32_t *versions = calloc(sizeof(int32_t), imageCount);
for (uint32_t idx = 0; idx < imageCount; idx++) {
    names[idx] = _dyld_get_image_name(idx);
    versions[idx] = NSVersionOfLinkTimeLibrary(names[idx]);
}

If I'm understanding dyld.h properly, this should get you a list of all the currently loaded mach-o images and their link-time versions. Any mach-o image with a link-time version of -1 wasn't linked against from the main executable.

Upvotes: 1

Related Questions