• 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: conditionally linking to a static lib?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditionally linking to a static lib?


  • Subject: Re: conditionally linking to a static lib?
  • From: Greg Guerin <email@hidden>
  • Date: Thu, 8 Oct 2009 14:34:29 -0700

John Mikros wrote:

In our project, we have a bunch of targets that build static libs, and then we link those libs into a final executable. The targets for the static libs are dependencies of the target for the final exe.

One of those targets needs to be built only for x86 and not for ppc. We would like to not wrap each of the source files with #ifdef __i386__, so we set the architectures build setting for that one target to "i386" instead of "i386 ppc".

But, we get link warnings when the ppc executable gets linked with "file is not of required architecture".

So, I took that library out of the "Linked Libraries" for the executable, and added -lmystaticlib to "Other Linker Flags" for just i386. This gets rid of the warnings.

But, this has the side effect that the dependency checking doesn't work such that if the lib gets rebuilt, it doesn't cause the executable be relinked.

Is there a way that I can get rid of the warnings and still get the executable to be automatically relinked when needed?


Maybe make an empty or do-nothing static lib for ppc. I'm not sure if you can get away with it being completely empty, so maybe this function, compiled for i386 and ppc:

  void nothing()
  {  ;  }

Or if the ppc app doesn't ever reference any of the functions residing in the i386-only lib, then just compile that lib for both ppc and i386. Since the ppc executable never references any symbol from the static lib, then it should never link any of the modules into the executable. The ppc-code doesn't even have to work; it's not referenced, so it won't be used. This exploits the inherently conditional nature of static libs, in which modules are only linked into an output if a symbol from it is referenced. If no module is referenced, then no module appears in the output.

  -- GG

_______________________________________________
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: conditionally linking to a static lib?
      • From: John Mikros <email@hidden>
  • Prev by Date: Xcode 3.2.1 is available at connect.apple.com
  • Next by Date: Re: Xcode 3.2.1 update is available in iPhone OS 3.1.2 SDK
  • Previous by thread: Re: conditionally linking to a static lib?
  • Next by thread: Re: conditionally linking to a static lib?
  • Index(es):
    • Date
    • Thread