I'm building WebRTC for iOS. To do that, I'm using the following bash script:
# Set flags to compile in arm64
export GYP_GENERATORS="ninja"
export GYP_DEFINES="build_with_libjingle=1 build_with_chromium=1 libjingle_objc=1 OS=ios target_arch=arm64"
export GYP_GENERATOR_FLAGS="output_dir=out_ios_arm64"
export GYP_CROSSCOMPILE=1
# Generate metadata for compile
gclient runhooks
# Compile webRTC in Release and verbose mode
ninja -v -C src/out_ios_arm64/Release-iphoneos AppRTCDemo
In the same machine and the same dir, I have compiled for armv7 and now when I try to build with the code above, the library is compiled for armv7. Maybe I have some metadata info in my dir that I'm not removing or something but I understand that if I set target_arch=arm64 in my GYP_DEFINES I should see my library compiled for this arch. Any idea what could be happening?
P.D: I need to build for both (armv7 and arm64) in order to generate with lipo an universal lib.
Related
I've been trying to cross-compile a static C library for use in an iOS application.
I figured that this can be achieved by wrapping the headers and binaries in an XCFramework, but the compiled library is for an x86_64 architecture, so it can't run on iOS.
What I did was the following:
export IOS_SDK_LOC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
export AARCH64_FLAGS="-arch arm64 -isysroot $IOS_SDK_LOC "
./configure --host=arm_apple_darwin --build=x86_64_apple_darwin --target=x86_64_apple_darwin
\ CFLAGS=$AARCH64_FLAGS CPPFLAGS=$AARCH64_FLAGS
I initially tried to just have the CFLAGS, but ended up passing the same arguments as CPPFLAGS as well following the answer at Can't cross compile C library for arm (iOS)
In either case, I get the same error:
configure: error: cannot run test program while cross compiling
How should I go about compiling my library in this case?
The workaround I found for compiling an arm64 static library on the same machine was to install QEMU (machine emulator), with the target OS in mind.
As luck would have it, Jonathan Afek from Aleph Security recently wrote a frame buffer for iOS QEMU, making it particularly easy to work with now.
More information here: https://www.reddit.com/r/jailbreak/comments/kxr0v8/news_ios_qemu_is_getting_a_graphical_display_ios/
How can I compile WebRTC iOS framework with Bitcode enabled. Currently I have to disable the Bitcode of my project due to WebRTC framework.
You will need to build it yourself.
Something like:
# Clone the depot tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# Add the tools to the path
export PATH=$PATH:"`pwd`/depot_tools"
# Download the WebRTC source code
mkdir webrtc_ios
cd webrtc_ios
# This will take some time
fetch --nohooks webrtc_ios
gclient sync
# Let's start building
cd src
# Build the framework, remove --arch "arm64 x64" to build ALL architectures, including 32 bit
tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 x64
# The framework is at out_ios_libs/WebRTC.framework
Documentation: https://webrtc.github.io/webrtc-org/native-code/ios/
Update:
Starting with Xcode 14, bitcode is no longer required (see release notes), and no longer supported in submissions.
The google WebRTC neglected to fix an ARM build issue with bitcode for so long, they just waited it out...
the --bitcode option is no longer supported by the build script.
To continue building using my instructions, remove it:
tools_webrtc/ios/build_ios_libs.py --arch arm64 x64
according to the official doc, you have to compile manually. More details there:
main page: https://webrtc.org/native-code/development/
iOS page: https://webrtc.org/native-code/ios/
bottom of the page (last paragraph) includes instructions to build with bitcode support:
To build the framework with bitcode support, pass the --bitcode flag to the script like so
python build_ios_libs.py --bitcode
I moved from XCode 6 to XCode 7 and without any changes to the source, or project, or anything my Archive builds started to fail.
After research on the error that lipo produced:
lipo:.../Release-iphoneos/libSDWebImage.a and .../Release-iphonesimulator/libSDWebImage.a have the same architectures (i386) and can't be in the same fat output file
I found that the following:
In XCode 6 the lipo -info returns Architectures in the fat file: .../Release-iphoneos/libSDWebImage.a are: armv7 arm64 and Architectures in the fat file: .../Release-iphonesimulator/libSDWebImage.a are: i386 x86_64 which is correct. I have arm for iphone device and i386 for iphone simulator.
In XCode 7 these two files are the same, and have the i386 architecture! So framework scripts that uses lipo to join these two .a files into one fails.
Why XCode 7 suddenly stopped building my SDWebImage framework for arm? The project settings are unchanged, the library is the same, the scheme has Archive set to Release. Please help.
iMac:~ lukasz$ lipo -info /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphoneos/libSDWebImage.a
input file /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphoneos/libSDWebImage.a is not a fat file
Non-fat file: /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphoneos/libSDWebImage.a is architecture: i386
iMac:~ lukasz$ lipo -info /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphonesimulator/libSDWebImage.a
input file /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphonesimulator/libSDWebImage.a is not a fat file
Non-fat file: /Users/lukasz/Library/Developer/Xcode/DerivedData/…-etcsjmgakpylpmgchumhnsqpyrev/Build/Intermediates/ArchiveIntermediates/adhoc-stage/BuildProductsPath/Release-iphonesimulator/libSDWebImage.a is architecture: i386
I ran into the same problem trying to build a multi-architecture framework on Xcode 7. It seems like you are building a static library, which is different, but could be related. I'm assuming you are using xcodebuild command (in an Aggregate target run script?) to build your library for different SDKs and then doing lipo at the end to join all of them.
The problem for me was that the framework/library being built is located in the build/UninstalledProducts folder, and what lives in the BUILD_DIR are symlinks to that. So most likely the libraries in your Release-iphoneos and Release-iphonesimulator are aliases to the same one, hence you see that they have the same architecture (i386 in your case).
To avoid this, navigate to the 'Build Settings' of your static library target in Xcode and ensure the following under 'Deployment':
Deployment Location is NO for release
Deployment Postprocessing is NO for release
You should see that the build no longer outputs UninstalledProducts folder and that all libraries/frameworks built in the BUILD_DIR are unique files, which should now have the correct architectures. You can then do whatever you like with them using lipo. You might have to delete your DerivedData before attempting the above.
For me, the fix was to set the 'Skip install' from Yes no No (which is the default). So insure that in addition to other two options mentioned by Andrew Wei. +1 for great analysis dude.
I need a network library for my c library so I can use it on both iOS and android. I've been searching around and tried to build libcurl as a static library but wasn't successful.
I built it with the following settings
$ export CC="clang"
$ export CFLAGS="-Wall -g -std=c11 -pipe -Os -gdwarf-2"
$ ./configure --enable-static
make install
It runs fine when I test the library with my test.c library. However, when I run it on my iOS project, I got a mismatch on CurlchkszEQ(long, CURL_SIZEOF_LONG)
I think the problem was that CURL_SIZEOF_LONG is set to be 8 while long in iOS is 4.
Does anyone know what went wrong with my config setting?
You want to cross-compile libcurl for iOS but the problem here is that you use clang which by default produces 64-bit x86_64 object files.
In other words you need to work with the iOS toolchain (xcrun -sdk iphoneos clang), provide the right architecture flag(s)[1] (e.g -arch armv7) and use the right sysroot path.
I recommend you to refer to:
curl-ios-build-scripts: a collection of handy scripts used to build (lib)curl for iOS 5+ and OSX 10.7+,
or, http://seiryu.home.comcast.net/~seiryu/libcurl-ios.html which provides a ready-to-use a precompiled binary.
[1]: you may want to produce a fat library that targets ARMv7, ARMv7s and i386 (simulator) architectures.
i'm trying to use Google's v8 in my iPhone Application.
I built the libraries using "make arm" as stated on Google's website.
Unfortunately I get several linker errors telling me that the library is build "for archive".
The terminal tells me that the library's architecture is i386:
lipo -info libv8_base.a
input file libv8_base.a is not a fat file
Non-fat file: libv8_base.a is architecture: i386
So, how do I actually build a armv7 library?
BTW: I don't really know much about this library building stuff. Maybe I can only build for ARM on an actual ARM device? I don't get why I can't just download the prebuilt files anywhere, too.
You can find instructions to cross-compile for ARM on the v8 wiki.
When running on an x86 machine
make arm
builds a simulator, not an actual ARM binary.
You can also compile a release shell natively if you have ARM hardware:
scons arch=arm -j2
EDIT:
You may also want to learn about cross-compilation.
There is a simulator for armv7 built in the v8 source. If you check v8/src/arm/ you will find simulator files.
To build, make sure your CC, CXX and LINK are point to native gcc / g++ tools. And then do
Make arm.release -j8
This will make for arm and look into *.gypi files for more build options. Hope this is useful.