Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Littleodie914

macrumors 68000
Original poster
Jun 9, 2004
1,813
8
Rochester, NY
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)
 

Attachments

  • Screen shot 2010-10-07 at 2.13.57 PM.png
    Screen shot 2010-10-07 at 2.13.57 PM.png
    33.1 KB · Views: 166
Isn't the iPhone ARM and not PPC/Intel?
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.
 
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?
 
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?
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.)
 
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?
 
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?
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
 
Remember that i386 isn't the same as x86_64
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:
 

Attachments

  • Screen shot 2010-10-08 at 9.04.47 AM.png
    Screen shot 2010-10-08 at 9.04.47 AM.png
    28.9 KB · Views: 122
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.