Static Library Shared Between iPhone and Mac

Discussion in 'Mac Programming' started by Littleodie914, Oct 7, 2010.

  1. macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #1
    Hey guys, I have a static library containing a few model and utility classes. The static library is built for two different targets, one for the iPhone, one for the Mac.

    I have a Mac application that uses the static library, but I see the following error when I compile the Mac application. There are no compilation issues when building the static library.

    Code:
    ld: warning: in /Users/Craig/Documents/Xcode Builds/Debug.core.mac/libCore (Mac).a, file was built for unsupported file format which is not the architecture being linked (x86_64)
    Strange enough, both Architectures settings appear to be equal for both the library and the application itself. :confused:

    Edit: If I switch to a different architecture, things get even worse. When building the Mac application, I see, among many others:

    Code:
      "_OBJC_CLASS_$_NSMutableString", referenced from:
    
    
          objc-class-ref-to-NSMutableString in libCore (Mac).a(DataLoader.o)
    
    
    
     

    Attached Files:

  2. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
  3. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #3
    The static library produces two targets - one is built using the 10.6 SDK, the other is built using the iPhone SDK. I have a third target (the default) that builds both the Mac/iPhone targets to ensure the code is cross-platform.
     
  4. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #4
    Do you have the source, so you can rebuild the library with x86_64 support?

    What does

    file "/Users/Craig/Documents/Xcode Builds/Debug.core.mac/libCore (Mac).a"

    give you for output?
     
  5. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #5
    I do have the source, and the Architecture settings are the same as in the screenshot. Even if I uncheck the "Build only for current architecture" box, the errors occur.

    Note also that this same static library is being used in an iPhone application without any issues, it only occurs when being used in a Mac app. (Even though the static library produces two targets, one for Mac and one for iPhone, and the projects are using their respective versions of the library.)
     
  6. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
    #6
    Sounds like it doesn't have x86 built into it. Can you run the file command on the library file and tell me what it says?
     
  7. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #7
    I might be doing... not the right thing... :)

    Code:
    Laptop:Debug.core.mac Craig$ file libCore\ \(Mac\).a 
    libCore (Mac).a: current ar archive random library
    Edit: Running an 'otool -hv', I see this output (one line for each object file, all with cputype I386):

    Code:
    libCore (Mac).a(ServerBrowser.o):
    Mach header
          magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
       MH_MAGIC    I386        ALL  0x00      OBJECT     3       2336 SUBSECTIONS_VIA_SYMBOLS
    Edit 2: To make matters even more confusing, it seems my Mac version of the library is being compiled against the iPhone framework. I checked under the "Build" tab of the target's properties, and I had a hard time finding anything that sounded iPhone-related. Output of libtool on the Mac version:

    Code:
    Libtool "/Users/Craig/Documents/Xcode Builds/Debug.core.mac/libCore (Mac).a" normal i386
    cd /Users/Craig/Documents/Projects/MyProject/Core
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool -static -arch_only i386 -syslibroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk "-L/Users/Craig/Documents/Xcode Builds/Debug.core.mac" -filelist "/Users/Craig/Documents/Xcode Builds/Core.build/Debug-iphonesimulator/Core (Mac).build/Objects-normal/i386/Core (Mac).LinkFileList" -ObjC -framework Foundation -o "/Users/Craig/Documents/Xcode Builds/Debug.core.mac/libCore (Mac).a"
    
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC 
     
  8. macrumors 68000

    Joined:
    Mar 29, 2009
    Location:
    USA
  9. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #9
    Right, of course not, but if I'm attempting to build for all architectures, or even for only the current architecture, why is i386 the only one that is produced?

    And where should I look to change those settings? This is the Build tab of the Mac version of the library:
     

    Attached Files:

  10. thread starter macrumors 68000

    Littleodie914

    Joined:
    Jun 9, 2004
    Location:
    Rochester, NY
    #10
    I gave up, and ended just dragging-and-dropping the Core classes into my other two projects, under a "Core" group. It's a bit tricky to make sure that any new classes are added to the two projects, but the build issues are completely gone. :)
     

Share This Page