Run 32 bit library on iPhone 5s 64 bit - ios

I'am using zbar in my application. If I want to run it on my iPhone 5s with an 64 bit processor, I get the following errors:
Is it possible to use the 32 bit library on a 64 bit device, because I don't think, the library is going to be updated.

To summarize the comments above. A 64bit iPhone application requires all constituent libraries and frameworks to be 64bit. You can't mix and match. Leaving an application 32bit is non-optimal long term since iOS has to keep two versions of the system libraries loaded (32 and 64) as soon as a single 32bit app is run. Hence, you don't want to be the last app to support 64bit!
You can check if your library contains 64bit code using lipo. For example, here's the SBJson framework in 32bit:
$ lipo -info SBJson.framework/SBJson
Architectures in the fat file: SBJson.framework/SBJson are: armv6 armv7 i386
and with 64bit code
$ lipo -info SBJson.framework/SBJson
Architectures in the fat file: SBJson.framework/SBJson are: armv7 armv7s i386 x86_64 arm64
In the case of zbar, if it's not available you could always try compiling yourself from source.

Related

Convert library.a for macOSX to library.a for iOS

Is there a way to convert a library that is built for macOS to a library that I can use in my iOS project. I'm getting an error in my app that follows:
/Users/edwardpizzurro/Desktop/LibreriasAlternativas/LibreriasAlternativas.xcodeproj Building for iOS, but the linked library 'libsndfile.a' was built for macOS.
In general, it's not possible and you have to rebuild your library specifying iOS architecture.
To get more info about your library, run
lipo -info libsndfile.a
It'll give you architectures like armv7 armv7s i386 x86_64 arm64. A default architecture for iOS is arm64, while for MacOS it's x86_64 (we are not speaking of new M1 hardware). So most probably for your libsndfile.a you'll get only x86_64.
This will mean you need to build libsndfile by yourself.
Here are releases of this lib, there's no arm64 here: https://github.com/libsndfile/libsndfile/releases
So you have to donwload the repo: https://github.com/libsndfile/libsndfile
And use smth like Autotools to build it for your desired architecture.
A rough example of what you'll have to do it here: Can't cross compile C library for arm (iOS)
While it's quite specific for each library.

Which architectures are used when I compile something for iOS?

I try to understand the different architectures for iOS, and when I need which.
I have a Hello World example. Is my assumption correct that, if I run it in the Xcode Simulator, I need to compile everything including my dependencies for x64 (because it's running on my computer).
And for my attached iPhone it's getting compiled for only that architecture. And for Generic iPhones my example will be a multiarchitecture app (arm64 arm64 armv7 armv7e) so it can run on a variety of architectures. Is that correct?
Thanks for your insight.
P.S. So if my example links foo.a, but foo.a is just arm64 arm64 armv7 armv7e but not x64, I could compile my app for iPhones but not run it in my simulator
This is essentially correct although you have two arm64 listed above; it should be arm64 and arm64e.
As to what architectures get built, it depends on the setting "Build Active Architecture Only". The typical Debug config has this set to Yes, so it only builds for the architecture of the device that you're targeting.
A Release config has this set to No, so it compiles for all architectures specified in "Architectures", which usually $(ARCHS_STANDARD), i.e., the architectures you listed.
As to your PS, you are correct that a .a file with only ARM archs could not be linked to a Simulator target.

Will Using a 32-bit Library Make My Entire App Run in 32-bit Mode? [duplicate]

I'am using zbar in my application. If I want to run it on my iPhone 5s with an 64 bit processor, I get the following errors:
Is it possible to use the 32 bit library on a 64 bit device, because I don't think, the library is going to be updated.
To summarize the comments above. A 64bit iPhone application requires all constituent libraries and frameworks to be 64bit. You can't mix and match. Leaving an application 32bit is non-optimal long term since iOS has to keep two versions of the system libraries loaded (32 and 64) as soon as a single 32bit app is run. Hence, you don't want to be the last app to support 64bit!
You can check if your library contains 64bit code using lipo. For example, here's the SBJson framework in 32bit:
$ lipo -info SBJson.framework/SBJson
Architectures in the fat file: SBJson.framework/SBJson are: armv6 armv7 i386
and with 64bit code
$ lipo -info SBJson.framework/SBJson
Architectures in the fat file: SBJson.framework/SBJson are: armv7 armv7s i386 x86_64 arm64
In the case of zbar, if it's not available you could always try compiling yourself from source.

converting ios 3rd party APIS to 64bit architecture

i am new in ios development and now days working on an app that has been designed in 32 bit architecture with lots of 3rd party apis and cocopods usage in it.
As apple has decided to move all the apps to 64-bit architecture, i'm unable to figure out if there's any api in my code that's not following the rules and is still in 32bit architecture.
is there any way to check that and to convert them for 64bit architecture support.???
You can use lipo -info to get the supported architectures. For example:
lipo -info mylib.a
Could give an output like:
Architectures in the fat file: mylib.a are: armv7 i386 x86_64 arm64
In this case, you see arm64, which is the 64-bit slice you want.
As far as upgrading your libraries, you'll need to rebuild the libraries yourself or download new versions with 64-bit support.

Using a 32-bit library in a 64-bit app

I have my project set up to run as 64-bit on supporting devices, and 32-bit otherwise. ZBarSDK is giving me an issue though. I get the error Undefined symbols for architecture x86_64.
Doing a lipo -info on the library file results in: armv6 armv7 i386
Is there a way to still compile my project for 64-bit and include this library?
No. 32-bit code cannot call 64-bit code and vice versa.

Resources