Xcode issue building 64-bit app with LibX library - ios

I'm trying to use libXl for iOS and it is giving me a linker error.
"missing required architecture x86_64"
I've changed the Architechture to standard but when I try to build for a 64 bit simulator, it gives me the linker error.
What needs to be changed to fix this error if I don't have the source code for the library?

Unfortunately, if you don't have the source code for the library and the library doesn't have a 64-bit slice, then you can't compile a 64-bit version of your app. (By the looks of things, even the commercial version of LibXL doesn't support 64-bit yet.)
Additionally, you can't mix 32 and 64 bit code/libraries within an app, I'm afraid. (If your app is 32 bit, the OS will load a 32 bit version of UIKit, etc. but that's as far as it goes.)
However, if you simply build your app as 32-bit if will run perfectly fine on 64-bit (i.e.: A7 processor+) devices.

Related

Xcode 14 deprecates bitcode - but why?

The bounty expires in 7 days. Answers to this question are eligible for a +50 reputation bounty.
mfaani wants to reward an existing answer.
Xcode 14 Beta release notes are out, all thanks to the annual WWDC.
And alas, the Bitcode is now deprecated, and you'll get a warning message if you attempt to enable it.
And I was wondering, why has this happened? Was there any downside to using Bitcode? Was it somehow painful for Apple to maintain it? And how will per-iPhone-model compilation operate now?
Bitccode is actually just the LLVM intermediate language. When you compile source code using the LLVM toolchain, source code is translated into an intermediate language, named Bitcode. This Bitcode is then analyzed, optimized and finally translated to CPU instructions for the desired target CPU.
The advantage of doing it that way is that all LLVM based frontends (like clang) only need to translate source code to Bitcode, from there on it works the same regardless the source language as the LLVM toolchain doesn't care if the Bitcode was generated from C, C++, Obj-C, Rust, Swift or any other source language; once there is Bitcode, the rest of the workflow is always the same.
One benefit of Bitcode is that you can later on generate instructions for another CPU without having to re-compile the original source code. E.g. I may compile a C code to Bitcode and have LLVM generate a running binary for x86 CPUs in the end. If I save the Bitcode, however, I can later on tell LLVM to also create a running binary for an ARM CPU from that Bitcode, without having to compile anything and without access to the original C code. And the generated ARM code will be as good as if I had compiled to ARM from the very start.
Without the Bitcode, I would have to convert x86 code to ARM code and such a translation produces way worse code as the original intent of the code is often lost in the final compilation step to CPU code, which also involves CPU specific optimizations that make no sense for other CPUs, whereas Bitcode retains the original intent pretty well and only performs optimization that all CPUs will benefit from.
Having the Bitcode of all apps allowed Apple to re-compile that Bitcode for a specific CPU, either to make an App compatible with a different kind of CPU or an entirely different architecture or just to benefit from better optimizations of newer compiler versions. E.g. if Apple had tomorrow shiped an iPhone that uses a RISC-V instead of an ARM CPU, all apps with Bitcode could have been re-compiled to RISC-V and would natively support that new CPU architecture despite the author of the app having never even heard of RISC-V.
I think that was the idea why Apple wanted all Apps in Bitcode format. But that approach had issues to begin with. One issue is that Bitcode is not a frozen format, LLVM updates it with every release and they do not guarantee full backward compatibility. Bitcode has never been intended to be a stable representation for permanent storage or archival. Another problem is that you cannot use assembly code as no Bitcode is emitted for assembly code. Also you cannot use pre-built third party libraries that come without Bitcode.
And last but not least: AFAIK Apple has never used any of the Bitcode advantages so far. Despite requiring all apps to contain Bitcode in the past, the apps also had to contain pre-build fat binaries for all supported CPUs and Apple would always only just ship that pre-build code. E.g. for iPhones you used to once have a 32 Bit ARMv7 and a 64 Bit ARM64 version, as well as the Bitcode and during app thinning, Apple would remove either the 32 Bit or the 64 Bit version, as well as the Bitcode, and then ship whats left over. Fine, but they could have done so also if no Bitcode was there. Bitcode is not required to thin out architectures of a fat binary!
Bitcode would be required to re-build for a different architecture but Apple has never done that. No 32 Bit app magically became 64 bit by Apple re-compiling the Bitcode. And no 64 bit only app was magically available for 32 bit systems as Apple re-compiled the Bitcode on demand. As a developer, I can assure you, the iOS App Store always delivered exactly the binary code that you have built and signed yourself and never any code that Apple has themselves created from the Bitcode, so nothing was server side optimized. Even when Apple switched from Intel to M1, no macOS app magically got converted to native ARM, despite that would have been possible for all x86 apps in the app store for that Apple had the Bitcode. Instead Apple still shipped the x86 version and let it run in Rosetta 2.
So imposing various disadvantages onto developers by forcing all code to be available as Bitcode and then not using any of the advantages Bitcode would give you kinda makes the whole thing pointless. And now that all platforms migrated to ARM64 and in a couple of years there won't even be fat binaries anymore (once x86 support for Mac has been dropped), what's the point of continuing with that stuff? I guess Apple took the chance to bury that idea once and for all. Even if they one day add RISC-V to their platforms, developers can still ship fat binaries containing ARM64 and RISC-V code at the same time. This concept works well enough, is way simpler, and has no downsides other than "bigger binaries" and that's something server side app thinning can fix, as during download only the code for the current platform needs to be included.
Apple Watch Series 3 was the last device to not support 64-bit. (i.e. i386 or armv7)
Apple has now stopped supporting the Apple Watch Series 3. [1] They would have been happy to drop support for bitcode.
[1] https://www.xda-developers.com/watchos-9-not-coming-apple-watch-series-3
xcode remove armv7/armv7s/i386 targets support. bitcode use for build different cpu targets. but now all devices might be arm64 . and now no more developer use this tech. so deprecated maybe a wise choice
Bitcode was always pointless, as even if you compiled bitcode to another architecture, there's high chance it won't actually work because the ABI is different. For example, when you compile C program, the libc headers actually are different for every architecture. I'm glad they are finally getting rid of it, as it caused more problems than solved. At most they could've done is re-optimize the binary for the same architecture, or similar enough architecture. There is also the problem of unwanted symbols leaking in bitcode builds, so you either have to rename/obfuscate those or get hit by collisions (big problem if you are a library/framework vendor).

Will Apple re-run macros when using bitcode?

With bitcode, Apple say they can re-build my application on demand, whenever they think it is necessary.
If my source code contains preprocessor macros, when will those run?
When I build and archive my IPA locally? Or also when Apple re-builds the app?
I'm considering both custom macros, as well as built-in ones such as __DATE__ and __TIME__. Which date/time will it get if Apple re-builds the app in the app store?
No; Apple will have a 32 bit version and a 64 bit version for your app in bit code; that's all. All the #define's will be evaluated by your compiler and not be sent to Apple.
With what they have Apple can easily produce a new version of your app that will run on new versions of the ARM processor. They most likely could build a new version that would run on an Intel processor instead of an ARM processor (while their instruction set and implementation are very different, how these chips behave is actually very similar). Building a version for a little-endian PowerPC would be possible; a version for big-endian PowerPC would quite likely not work if your app includes code that needed to be different on a big-endian processor.
__DATE__ and __TIME__ would be the ones that were valid when you built the app.
The result of Apple building a new version for a new processor from bitcode should be exactly the same as if you had submitted the app with code for that processor. Obviously you don't have a compiler for ARM13 which will be introduced in 2022, but if Apple builds that version from your submitted bit code, it should be as if you had had that compiler today.

Augmented reality webcame error

I'm working an augmented reality application using unity 5.
I'm having an error:
Failed to load 'Assets/Plugins/QCARWrapper.dll', expected 64 bit architecture
(IMAGE_FILE_MACHINE_AMD64), but was IMAGE_FILE_MACHINE_I386. You must
recompile your plugin for 64 bit architecture.
any help?
Had the same issue, and had to install Unity 32bits to get Vuforia working the properly on my project.
You can download the latest 32 bit Unity Editor from here.
If you are looking for a specific version, here is the full list.

Do I need to do anything special for 64-bit apps written in Swift?

I am new to iOS development. I have developed an app entirely in Swift.
I was wondering if apps developed with Swift (Xcode 6.0.1) need any special care to meet the 64-bit requirements?
I am using the default build settings:
Standard architectures(armv7, arm64) – $(ARCHS_STANDARD)
Is there anything I need to do to make sure it meets 64-bit requirements?
By default 64 bit architecture is preferred (see How to remove arm64 support from Xcode 6?). You have to go out of your way to remove arm64 (64 bit) support (in Xcode 6).
In your code, most commonly you should use things like Int which automatically adjusts to the device's architecture (see this for more detail) to ensure support, instead of Int32 or the 64 bit variant; However this is only for performance reasons (which is still important!).

About arm neon compiling

Some of my code reference a library which use arm_neon.h; when I tried to compile using "Simulator", I received a bunch of errors.
I am using LLVM 4.2 compiler, what should I do to get it compiled with arm neon?
You can't compile ARM NEON code for the simulator because the simulator doesn't execute ARM machine code, it executes i386 machine code. See here for more info, but here is a snippet:
Don’t forget that you’ll need to disable the NEON code at compile time when building for the simulator, as your application is compiled for x86 when targeting the simulator, and NEON code will cause build errors in this context. This means you always need to also write a generic C version of the algorithm, even if you only target the iPad, or you won’t be able to run your application in the simulator.

Resources