Cannot compile a static library for arch armv7 - iphone

I have a static library (very simple, no includes) which builds fine with "-arch i386", I can use the demo method in this library and everything is fine. As usual I have an .a file to link in my project.
Unfortunately I want to use this library in an iOS project, so when I use the iPhone Simulator everything is fine with the library built with "-arch i386" (because this is the processor the simulator uses). If I now want to build the library with "-arch armv7" (or "-arch armv6") for my ARM-based iPhone device I get in Eclipse and in Xcode the same error message: (in Xcode:) llvm-gcc-4.2 failed with exit code 255. Same exit code in Eclipse (255). With "i386" everything works.
Must I install anything in addition to my Xcode 4.2.1 on OSX Lion to make compile the lib for my ARM-Device?

The issue lies in the fact that Xcode 4 builds static libraries for each build rather than one unified universal build. So my guess is that you are just adding the build for debug-simulator and not for debug-device. Your best bet, add a script to your static library to build them all into one.
This post here on SO saved my life. Hopefully it will help you too.

Related

Building project for M1 Mac fails because of architectures it believes are missing

We have a project that uses many AWS libraries. On first attempting to build it, using carthage, it downloaded binaries and it did not build at all. So we ran carthage --no-use-binaries and it built the libs.
Then this error occurs:
LoginService.swift:9:8: Module 'AWSMobileClient' was created for incompatible target arm64-apple-ios9.0: ..Carthage/Build/iOS/AWSMobileClient.framework/Modules/AWSMobileClient.swiftmodule/arm64.swiftmodule
Based on this stack overflow thread, we add arm64 to excluded architectures for the simulator.
Which makes all the aws code compile (yay) but then, this error occurs trying to use a framework that is coming in via the Swift Package Manager:
[].swift:10:8: Could not find module 'Parma' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator
So it wants the x86 version of this lib, and cannot find it.
The app does run on the phone now. But not the simulator of course. Not sure if there is a way to figure out which architectures are built by SPM? or control it. I did reset the SPM cache after excluding the arm64 arch.
I think the best solution for getting this working on M1 is to use XC-Frameworks.
carthage update --use-xcframeworks
This will only build the valid archs you need. If you have any dependencies that don't support XCFrameworks yet you'll have to run lipo to remove x86 simulator targets in your build phase.
Hey I've come across the issue. Just open your old project by Rosetta and build it. Then uncheck open by Rosetta and build it. It helped me to open old project on m1

Xcode 8 Builds Successfully but Fails on Archive

I am writing a program in Swift using Mac OS Sierra and Xcode 8.3.2 and am using the RandomKit module from: https://github.com/nvzqz/RandomKit. I am using the basic Swift Package Manager to import the package into my project.
My program builds and runs fine, but when I go to archive it, I get an error saying "No such module 'RandomKit'
It highlights my code:
import RandomKit
Does anyone know why this would build and run but fail when I attempt to archive?
By default, when you Run in XCode, it uses the Debug configuration, and when you Archive, it uses the Release configuration. In Build Settings, look at the Build Active Architecture Only setting. By default, it is Yes for Debug, and No for Release.
This means that when you Run, XCode only builds for the simulator's architecture, but when you Archive, it builds for all possible iOS architectures.
Now, look at the settings for RandomKit to see what architectures it is built for. It needs to include all of the iOS architectures, like arm64, armv7, and armv7s.
After probably 4 hours I finally figured it out. I think this must be a bug in Xcode, but here is my workaround.
In this folder:
~/Library/Developer/Xcode/DerivedData/<My App Name>/Build/Products/Debug
I found RandomKit.framework and ShiftOperations.framework. I copied those two files into the root directory of my Xcode Project, and then linked the frameworks under General in my Xcode Project.
Linking Frameworks

Can't build iOS/iPhone app as anything other than i386

I am completely new to the iOS/iPhone/XCode world, so if you guess is between something rather complex and something so simple that everyone should know, I'd go with the simple answer. :-)
Okay, so I have inherited an iPhone project that we had outsourced to another company. My only objective right now is to be able to build the dang thing. I set up XCode 4.2 and installed the proper SDKs. I loaded up the project and everything seems good to this point. However, when I build, I get errors from what I believe to be the linking stage of the build. I'm not entirely sure because the statuses change quickly when building. The error I get is the following:
From what I have been able to find online, it seems that one of the libraries I am using was not compiled for the i386 platform. To start, this doesn't make sense to me because the libraries that I am using (where these errors are coming from) are currently included as sub-projects and produce .a files which I thought were arch-independent (am I wrong here??). Also, I can't find anywhere in the project where I've instructed XCode to build to an i386 architecture. This is what I've done so far:
Made sure that the file in which these errors arose was included into the "Compile Sources" section of the Build Phase tab (the .m file)
Set my architectures to armv6 and armv7 and set the Build Active Architecture Only to no. (See images below)
Main Project Config
Sub-Project Config
Event when I build using the release configuration, I still get this error and I'm not sure why. Everything that I am looking at in my build config seems to indicate that I should be building everything in an arm architecture.
You are getting errors because you messed with the architecture settings. You should not fix those towards ARM code but allow i386 as well.
Right now, one of more of your (sub)-projects build ARM code only, resulting into a linker error once you try to build a simulator version. That is happening because your Architecture settings are not as they should be.
Note your setting for Any iOS SDK, that one is incorrect as it builds only ARM code. Remove those settings entirely by using the backspace key on your keyboard after selecting that specific setting (single-click).
And this is how it should be:
$(ARCHS_STANDARD_32_BIT) resolves to ARMV7 when building device specific code and i386 when building simulator specific code. Including ARMV6 code as per my screenshot is only needed if you plan to serve the results to older iOS devices (iPhone 3G and below).
Once those settings are active in all (sub)-projects, everything should work smoothly.
For creating a universal library out of a project, useful if you plan to distribute a static library to other developers, use LIPO.
Example:
lipo input_library_1.a input_library_2.a -create -ouput output_library.a
Lets say input_library_1 was i386 specific (simulator) and input_library_2 was ARM specific (device), this will join them into a universal version usable for both simulator and device.
It seems like you have been trying to link to static library built for devices(armv6 or armv7). When your building for the simulator the architecture will be i386. So you getting all these nasty linking errors. Solution is to include the library compiled for simulator as well in your project.

How to make Xcode 3.2.3 build a specfic architecture?

I'm getting the following error when including static libraries:
missing required architecture i386 in
file
This worked 30 seconds previously, and only failed when I upgraded to Xcode 3.2.3. I've used "file" command to check - and, yes, XCode is building completely the wrong architecture (armv6 + armv7 instead of i386).
This seems to be a major bug in latest Xcode, where Apple has re-written the build / compile / link settings. There's a note in the release notes saying very vaguely that they've "Changed it" because it used to be "confusing". This is not helpful.
The build settings for the library VERY clearly say:
"Valid architectures: i386"
There's no confusion here - Xcode is building something other than what the target says it should.
The question is: how do you un-break this? How do you force Xcode to do what it's supposed to? I've re-installed Xcode from scratch, cleaned everything, and manually inspected the build files. There's nothing wrong (and, of course, it worked perfectly in xcode 3.2.2)
After considerable research, I believe the answer is:
"this is now impossible - Apple has deliberately hard-coded XCode to ignore build settings"
However, I've come up with a script that automatically builds ALL platforms of a project (which you HAVE to do with static libraries - you don't have much choice now, because Apple has disabled Targets), and the script could easily be modified to do all targets, instead of all platforms:
Build fat static library (device + simulator) using Xcode and SDK 4+
Right click on your Target app under Targets and make sure that the Base SDK is set to iOS.

iPhone library: file is not of required architecture

I have searched for hours however I still have no clue what is wrong with my configuration.
My project uses a self-written libray (myLib). This library is compiled to work only for simulator and it works perfectly there.
What do have to change so it compiles for my iPhone Device as well?
This is my current warning:
ld: warning: in /.../myLib.a, file is not of required architecture
This is my configuration (of myLib.a)
I found a lot of articles explaining the reason for this error however I could not find a solution:
The simulator runs on an x86
architecture, while the device uses an
ARM architecture.
What do I have to change to get my library working on my iPhone?
Thanks
Edit:
What I did so far:
Cleaned both projects
Set library to 'Device' (3.1)
Built the library
Dragged the .a file of my library into my application
Result:
This works in simulator but setting the active sdk to device still raises a file is not of required architecture error.
I also tried mahboudz ( thanks for your support) link.
It explains howto built the project using a shell script.
However XCode keeps complaining that the library file is of the wrong architecture and the build fails.
This has to be a really stupid beginners mistake.
You need to add both .a files,the one built for the device (build/$config-iphoneos)and the one built for the sim (build/$config-iphonesimulator) to the new project. Make sure you name them differently before dropping them in. This is how admob and similar offering ship their static libs.
You need to compile your library for Intel so the Simulator can use it (which I gather you have done already), and then compile it for ARM, so it can run on the iPhone. Then you have to merge the two libraries. There are different ways to accomplish that, or make it more automatic.
Here are some links to help you:
http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html
http://www.clintharris.net/2009/iphone-app-shared-libraries/
I've met the same problem too. But seems you don't need to drag two .a files into the app project to solve this problem. This is what I did:
Drag the static library project into app project's framework group
"Get Info" for the target in app project
Set the direct dependency of static library
Make clean all unnecessary builds(for example the simulator build) in the static library project
Build in the app project