如何构建Cocoa Touch Framework for i386和x86_64架构? [英] How to build Cocoa Touch Framework for i386 and x86_64 architecture?
问题描述
在构建Cocoa Touch框架(Swift或Object-C)并将其添加到另一个项目作为嵌入二进制文件后,我得到以下错误消息,当我尝试生成
After building a Cocoa Touch framework (Swift or Object-C) and adding it to another project as "Embedded Binaries" I get the following error message when I try to build
missing required architecture i386
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
i386 更改为架构构建设置...
Following various existing answers and extended research I already added i386 to the Architectures build settings …
但这似乎没有效果。当我检查使用
However this doesn't seem to have an effect. When I check using
lipo -info TesterFrameworkObjC
我只能得到
Architectures in the fat file: TesterFrameworkObjC are: armv7 arm64
... i386(和x86_64)不应该出现在这里吗?我缺少什么?
… shouldn't i386 (and x86_64) appear here as well? What am I missing?
(我为iOS 8.2使用Xcode 6.2 +版本)
(I am using Xcode 6.2 + building for iOS 8.2)
使用此版本 build script 我可以为Swift版本的框架构建缺少的体系结构。
Using a version of this build script I am able to build the missing architectures for the Swift version of the framework.
但是当我添加这个框架到我的应用程序,我仍然得到错误
However when I add this framework to my app and build I still get errors
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$__TtC20TesterFrameworkSwift18TestFrameworkSwift", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture x86_64
查找在模拟器的最终构建文件夹构建
Looking at the final build folder building for the simulator
Build/Products/Debug-iphoneos/TesterFrameworkSwift.framework/
我可以看到架构仍然缺失,虽然他们是框架的一部分(如图所示)。在构建应用程序时,如何确保我的框架的所有正确的架构构建都包含在内?
I can see that the architectures are still missing although they were part of the framework (as shown). How can I ensure all the right architecture builds of my framework are included when building the app?
查看所有的错误消息给我,它看起来像不是实际上有错误的产品/ archictures构建,但一步之后,有链接器没有使用正确的路径。不确定如何正确。
Looking at all the error messages to me it looks like the issue isn't actually to have the wrong products/archictures being built but one step later there the Linker isn't using the correct paths to them. Not sure how correct this.
推荐答案
This is the same problem that I had.
看起来这是一个Xcode,它是一个Xcode bug,我解决它通过添加一个构建脚本。
这将只是编译您的库与所有的架构,并 lipo
它到胖二进制映像。
Seems this is a Xcode bug, I workaround it by adding a build script.
It will just compile your library with all architectures, and lipo
it to fat binary image.
另请注意
查看构建模拟器的最终构建文件夹
Looking at the final build folder building for the simulator
/Products/Debug-iphoneos/TesterFrameworkSwift.framework /
Build/Products/Debug-iphoneos/TesterFrameworkSwift.framework/
您在iphone build文件夹中查找x86_64和i386映像, Debug-iphonesimulator / TesterFrameworkSwift.framework /
you are looking x86_64 and i386 images in iphone build folder, they should be in Debug-iphonesimulator/TesterFrameworkSwift.framework/
在脚本中还有一个递归问题,
Also there is a recursion issue in your script, I've corrected it.
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules (from iphonesimulator build) to the copied framework directory
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/." "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
# Step 5. Convenience step to copy the framework to the project's directory
cp -R "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework" "${PROJECT_DIR}"
# Step 6. Convenience step to open the project's directory in Finder
open "${PROJECT_DIR}"
fi
6)点击cmd + B
(Build Project)
6) Hit "cmd + B"
(Build Project)
7)在 Finder中打开产品
>
8)向上导航1个目录(cmd +↑),您将看到Release-universal
目录。
8) Navigate 1 directory up ("cmd + ↑"), and you will see "Release-universal"
directory.
将会是您的fat / universal
图书馆,您已准备好了!
There will be your "fat/universal"
library, You are ready to go!
/ p>
You can check it via
file test.dylib
test.dylib: Mach-O universal binary with 4 architectures
test.dylib (for architecture i386): Mach-O dynamically linked shared library i386
test.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
test.dylib (for architecture armv7): Mach-O dynamically linked shared library arm
test.dylib (for architecture arm64): Mach-O 64-bit dynamically linked shared library
这篇关于如何构建Cocoa Touch Framework for i386和x86_64架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!