PDA

View Full Version : Static Library Shared Between iPhone and Mac




Littleodie914
Oct 7, 2010, 01:15 PM
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.

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:

"_OBJC_CLASS_$_NSMutableString", referenced from:


objc-class-ref-to-NSMutableString in libCore (Mac).a(DataLoader.o)



robvas
Oct 7, 2010, 02:04 PM
Isn't the iPhone ARM and not PPC/Intel?

Littleodie914
Oct 7, 2010, 02:36 PM
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.

robvas
Oct 7, 2010, 02:38 PM
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?

Littleodie914
Oct 7, 2010, 02:46 PM
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.)

robvas
Oct 7, 2010, 03:09 PM
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?

Littleodie914
Oct 7, 2010, 04:06 PM
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... :)

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):

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:

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

robvas
Oct 8, 2010, 07:30 AM
Remember that i386 isn't the same as x86_64

Littleodie914
Oct 8, 2010, 08:05 AM
Remember that i386 isn't the same as x86_64Right, 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:

Littleodie914
Oct 18, 2010, 05:21 PM
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. :)