简体   繁体   中英

Xcode static library seems to change architecture on build

Here's a bit of background before I dive into the question. My ultimate goal is to compile the source of a c++ static library for the architectures arm64, armv7, armv7s, i386, and x86_64, and then package the libraries into a fat library so that I can use them during iOS development. This will enable me to use the simulator and a device with the same library.

Here's my issue. I'm trying to test the i386 version of the library, on it's own, using the iPhone 5 simulator. I compiled the static library for i386 as follows:

./configure --enable-utf8-only --disable-shared --host=i386-apple-darwin LDFLAGS="-L." CC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" CXX="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"

then

make CXXFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk" CCFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk"

This resulted in my static library, libtest.a . I then ran the follow to verify the libraries architecture

jamespc:Desktop $ lipo -info libtest.a 
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: i386

Everything seemed to look good so far. Next I added the library to my Xcode project and tried to build the project. When building the project I get the following warning and error.

ld: warning: ignoring file 
    /Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a,
    file was built for archive which is not the architecture being linked (i386):
    /Users/cleandev/Library/Developer/Xcode/DerivedData/MyProject-hjtfdovfmdsubkejojqknkmqkzps/Build/Products/Debug-iphonesimulator/libtest.a
Undefined symbols for architecture i386:
    ...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Perplexed by error I ran lipo on my static lib again, this time using the path listed in the warning, in the derived data folder.

jamespc:Debug-iphonesimulator $ lipo -info libtest.a 
input file libtest.a is not a fat file
Non-fat file: libtest.a is architecture: x86_64

I'm confused as to why the library appears to have a different architecture associated with it when I take a look at it in the derived data.

Is the way I'm compiling the static library wrong? Is there something I might be doing wrong in my Xcode build settings? Thank you for taking the time to read my question

I guess the framework was not compiled for the iOS Simulator's architecture, which is i386. Xcode only compiles a framework for the target architecture.

Please follow this tutorial: http://www.raywenderlich.com/65964/create-a-framework-for-ios

It may help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM