• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Xcode-users] dylib Version Introspection?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xcode-users] dylib Version Introspection?


  • Subject: Re: [Xcode-users] dylib Version Introspection?
  • From: Peter O'Gorman <email@hidden>
  • Date: Wed, 01 Oct 2008 11:32:34 -0500

Chris Hanson wrote:
> On Oct 1, 2008, at 8:35 AM, Peter O'Gorman wrote:
>> I do not know if there is an easier way.
>
> There is. :)
>
> The header <mach-o/dyld.h> defines NSVersionOfRunTimeLibrary() and
> NSVersionOfLinkTimeLibrary().
>
> These are documented in the header and in the dyld(3) man page:
>
> http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/dyld.3.html

Duh. Silly me.

Still, they require the library to know its own name, whereas something
like this, does not (although this is also not exactly well tested :-p):

int getver() {
#ifdef __LP64__
  struct mach_header_64 * mh = &_mh_dylib_header;
  struct load_command * lc = (char*)mh + sizeof(struct mach_header_64);
#else
  struct mach_header * mh = &_mh_dylib_header;
  struct load_command * lc = (char*)mh + sizeof(struct mach_header);
#endif
  uint32_t i = 0;
  int retval = -1;

  for (;i < mh->ncmds; i++) {
    if (lc->cmd == LC_ID_DYLIB) {
      retval = ((struct dylib_command *)lc)->dylib.current_version;
      break;
    }
    else {
      lc = (char*)lc + lc->cmdsize;
    }
  }
  return retval;
}

I guess in the majority of cases the developer will know what the
library's name will be, so this is unnecessary, oh well, I think I will
just have another coffee and get back to work :)

Peter
--
Peter O'Gorman
http://pogma.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [Xcode-users] dylib Version Introspection?
      • From: Alexander von Below <email@hidden>
References: 
 >[Xcode-users] dylib Version Introspection? (From: Alexander von Below <email@hidden>)
 >Re: [Xcode-users] dylib Version Introspection? (From: Peter O'Gorman <email@hidden>)
 >Re: [Xcode-users] dylib Version Introspection? (From: Chris Hanson <email@hidden>)

  • Prev by Date: Re: [Xcode-users] dylib Version Introspection?
  • Next by Date: NDA dropped :)
  • Previous by thread: Re: [Xcode-users] dylib Version Introspection?
  • Next by thread: Re: [Xcode-users] dylib Version Introspection?
  • Index(es):
    • Date
    • Thread