xcode project-/target-settings-syntax for linker flag force_load on iPhone - iphone

I am confronted with the double bind. On the one hand, for one of the 3rd party static libraries my iPhone application uses, the linker flag -all_load has to be set in the application project or target settings. Otherwise, the app crashes at run-time not finding some symbols called internally from the lib. On the other hand, for another 3rd party static lib, -all_load must not be set on application level, or the app won't build thanks to a "duplicate symbols" linker error.
To solve this issue, I now want to use force_load instead of load_all, as it due to documentation it does the same like all_load, but only for the passed path or lib-file, instead of all libs.
The problem with force_load is, I do not have a clue how to pass a path or file as parameter with it, when passing it via XCode project- or target-settings. All syntax-possibilities I tried either lead xcode to thinking it's another linker flag instead of a parameter to the previous one, or the linker throwing syntax related errors, or the flag simply does nothing at all.
I also opened the .pbxproj-file in a text-editor to edit it to the correct command line syntax manually. But when reloading the project with XCode, it auto-changes the syntax into interpreting the parameter to force_load as a separate flag.
Anyone have an idea on this issue?

I just tried this. I've compiled a static armv6, armv7, and i386 fat binary of PCRE for use in my iPhone project. My project normally just has my library added to the project and that links fine. So I unchecked the target membership box for libpcre.a and rebuilt. As expected, I get a bunch of missing symbol linker errors for the pcre symbols. Then I opened the target settings window and edited the "Other Linker Flags" section. I added:
-force_load lib/pcre/libpcre.a
The lib directory is in the same directory as my project.xcodeproj file.
It linked fine so I know the force_load command worked (and I can see it added to the build flags when xcode builds the file).
Hope that helps.
Update:
I also tried adding a system library to the "Other Linker Flags" line like so:
-force_load src/pcre/libpcre.a -force_load ${SDKROOT}/usr/lib/libz.dylib
That worked too.

I just added force_load to our project and all is fine using the simplest syntax possible. The library is a dependency built in the same project. The library is therefore included on the link command-line twice: once as a normal input file and once as an argument to -force_load. You might want to put quote characters around the argument.
In fact, I've even got this working using configuration-dependent settings (because the path is obviously different for debug vs. release and device vs. simulator).
Good luck.

Related

WARNING: No screenshots were found for '( locale )' when trying to -exportLocalizations

I have a set of XCUITests that step through a Swift-based application. In the test plan configuration, I've selected to create Localization screenshots for the Dutch language.
When I then try to export the localization from XCode 12.5, I am able to see Dutch as an option and the screenshots export as I would expect.
However, when I attempt to actually export them from the command line (which I need to do in order to embed them in automation), I get an error:
xcodebuild -exportLocalizations -project 'test/test-inhouse.xcodeproj' -localizationPath localizations_output -exportLanguage nl -includeScreenshots
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportLocalizations -project test/test-inhouse.xcodeproj -localizationPath localizations_output -exportLanguage nl -includeScreenshots
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
--- xcodebuild: WARNING: No screenshots were found for '(
nl
)'
It doesn't matter what spelling I use, or if I put in Dutch. The error is always similar, it can't find the screenshots. I even looked at the project.pbxproj to ensure I'm putting it in exactly as is in the array.
I'm trying to not introduce further dependencies to our CI process, and simply use the built-in XCodeBuild command. Any thoughts on why it can't find the screenshots? Do I have to also specify what device type was built to or something?
It turned out that I was using a project instead of a workspace reference.
From what I can tell, a project is only a single compilable set of code and targets.
Our UITest target is actually a separate compilable object, so when I exported localizations with screenshots for workspace instead of project, it worked.

Apple Mach-O Linker error. "_OBJC_CLASS_$_SwiftObject" and Foundation undefined

I have a project with library in it. If I select library as a build target it builds successfully. If I select project as a target I have linker error Undefined symbols for architecture x86_64: and list of undefined symbols.
What is strange – all that symbols are standard things like "_OBJC_CLASS_$_SwiftObject", "Foundation.URLRequest.httpBody.setter : Foundation.Data?", "Swift.String.init(Swift.Substring) -> Swift.String".
This errors disappears when I'm removing SawtoothProtobuf.pb.swift file from build. However when building only lib project which contains this file everything builds successfull.
I'm running into a VERY similar issue too. I've tried to build a static library from swift framework to be accessible by obj-c by putting #objc and #objMember in front of all the required things and I'm getting similar errors as you are. It's weird though because it works in the framework works in the demo app from the code owner but it fails when I install it on mine...
Adding a blank swift file fixed it for me. I guess there needs to be some swift libraries loaded into the app which doesn't happen if there's no exposed swift code.

XCode 8.0, Building for Store Submission, Errors

Getting the following errors with XCODE 8.0. This was working fine with Xcode 7.x as far as we can remember.
ERROR ITMS-90087: "Unsupported Architectures. The executable for xxx.framework contains unsupported architectures '[x86_64, i386]'."
Does this mean that Apple is not smart enough not to include the simulator slice? We have to provide an SDK that has the simulator and does not?
ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'XXX' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."
But we are using the latest XCODE 8.0 version? What gives here?
ERROR ITMS-90125: "The binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's linker."
Not sure what this is. All Signing stuff is set correctly in all of the builds. Again, this was working fine before. We did use LIPO to make the universals. So maybe stripping the universals would do it????
WARNING ITMS-90080: "The executable 'Payload/mediumSDKSwift.app/Frameworks/VRSDK.framework' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."
All PIE stuff was working find, no changes, etc. All are set to NO for Position Dependent. Have been doing some reading on this and some have solved by flipping bits? hmmmm.....
ERROR ITMS-90087: "Unsupported Architectures. The executable for xxx.framework contains unsupported architectures '[x86_64, i386]'."
This is a known Apple bug.
Your other errors are resulting of manipulating an already signed product, so you have to code sign your product again after you sliced out the unsupported architectures.
Workaround:
The Carthage installer comes with a handy script, which I am using as an easy workaround.
1) Install Carthage
2) Add Build Phase Script
From Carthage site:
On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex: bin/sh), add the following contents to the script area below the shell:
/usr/local/bin/carthage copy-frameworks
and add the paths to the frameworks you want to use under “Input Files”, e.g.:
$(SRCROOT)/Carthage/Build/iOS/Box.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
...
Turns out we were providing a Universal Framework by mistake. Once this was solved all of the errors were solved.

Getting dyld_fatal_error after updating to Xcode 6 beta 4 using swift

I just recently downloaded Xcode 6 beta 4, and my swift project compiles with no errors but before it gets to my code I get a dyld_fatal_error just above start in the call stack.
and a breakpoint in some assembly code with a nop instruction
The console error I get is
dyld: lazy symbol binding failed: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
dyld: Symbol not found: __TFSsa6C_ARGVGVSs13UnsafePointerGS_VSs4Int8__
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/Sudoku
Expected in: /Users/username/Library/Developer/Xcode/DerivedData/Sudoku-dhrdonaeqzsgcvewndimxbbsltnc/Build/Products/Debug/Sudoku.app/Contents/MacOS/../Frameworks/libswift_stdlib_core.dylib
Just so you know the project still compiles, and runs fine with Xcode 6 beta 3.
Most extremely weird problems like this can be solved with a Clean & Build (or perhaps relaunch Xcode). You might also consider deleting the relevant folders from ~/Library/Developer/Xcode/DerivedData.
For sure this error is very unhelpful:
dyld`dyld_fatal_error:
-> 0x1200ad088 <+0>: brk #0x3
This of course occurs only on device, not the simulator. Another good reason to always test on a device.
Anyway, having had the same issue, a clean didn't work for me. Deleting DerivedData didn't help either. Also tried synchronising the Deployment Target versions. That didn't seem make any difference but I did it anyway.
Solution was to add any dynamic frameworks to Embedded Binaries setting under Target -> General:
Now I know that has been mentioned in other answers. However, if I can supplement by saying that any dependent dynamic frameworks must also be included.
So for example if you have a dynamic framework A that depends upon dynamic framework B, then it's necessary to have A and B added to Embedded Binaries.
Note that if the dynamic framework A depends upon any static library or framework, you will almost certainly be forced to create A as an umbrella framework that includes the dependant binaries.
Other considerations that may or may not be important. However did personally for me result in success were;
paths of each dynamic library in the Inspector were set to "Relative
to Group". In the screen grab above the path of the embedded binary
appears correct terminating with "build/Debug-iphoneos".
dynamic frameworks are in embedded binaries section. Static libs and
static libs wrapped up as frameworks are in Linked Frameworks
and Libraries. Nothing appears in both sections.
In setting this up XCode behaved strangely. The following proved successful:
Add the dynamic framework to the embedded binaries.
Find the new framework in XCode groups on the left and update the path to be
"Relative to Group" as described previously.
Delete the dynamic framework from embedded binaries.
Add the dynamic framework to the embedded binaries again. The path should now appear correctly.
Delete all references to the dynamic framework from the Linked Frameworks
and Libraries section.
I have just had this problem trying to link a custom iOS framework to my project, so for anyone out there who has this problem, it's to do with the copy files build phase.
I think that this error results when a file cannot be found. So create a copy files build phase in the appropriate target in your project. Then add the file (in my case the custom framework) to this phase (if it's a framework make sure to select the 'Frameworks' destination).
Cleaning, restarting, deleting etc didn't work for me.
I have a project containing another project. When I ran the project on iOS 7 and the contained project was accessed in code, the app stopped at the line below:
After many days, I saw that the deployment target for the container project was 7.0 (as can be seen below).
The contained project on the other hand, had a deployment target of 8.1 (as can be seen below).
Changing the deployment target of the contained project to 7.0 solved my problem!
The project was working fine on iOS 8 devices.
I had this issue recently and the problem for me was that I had added a library from the same project which wasn't listed in 'Embedded Binaries' from the 'General' section.
NOTE: If you add it in Embedded Binaries it will also add to the Linked Libraries section, possibly adding the same one twice.
Clean and build won't work. You'll need to delete he cache in ~/Library/Caches/com.apple.dt.Xcode* directories. Delete these and rebuild.
Do this every time you upgrade the beta.
I also faced the same issue and tried all the solution given above without any luck.
then what I have done to resolve that I really don’t have much I idea about. So there is Certificated called “apple worldwide developer relations certificate authority” in System group in keychain Access and due to some profile and certificate issue I randomly mark this certificate “Always trusted” from “Use System Defaults”. So this is causing this “dyld_fatal_error” crash to me. when I revert it back to “Use System Defaults” crash got resolved.
So guys if you are tried all the possible option to resolve this crash and didn’t succeed yet, try this also. It helped me, may help you as well.
Found this about this certificate.
This problem still occurs in Xcode 7, and it can happen for a variety of reasons (it seems). In my case, the iOS app with an included framework:
ran on the simulator fine
gave the error you described on the device
The answer was to NOT use linked libraries but rather Embedded Binaries under General.
Also see here: https://stackoverflow.com/a/34052368/8047
Adding the non-system Framework to "Embedded Binaries" inside the general tab of the main project worked for me.
As stated by bitwit, this will also add your framework to "Linked Frameworks and Libraries", so watch out for those duplicates.
Tested with Xcode 7.3.
Xcode 8.
Clean and build didn't work. I deleted the cache, deleted Derived data. After that, my pods configuration was broken, so i needed to install pods again. Pods Target configuration was set to a very old Valid architectures. setting to armv7 and armv7s, was ok to compile and no problems
You'll get this if your scheme has "Guard Edges" enabled in diagnostics when running on an actual device. "Guard Edges" only works in the simulator.
I was using cocoapods and had this problem as well when I updated to deploy target iOS 8 and added use_frameworks! to my Podfile. I was able to fix it by adding the following line to my Podfile:
link_with 'TargetName1', 'TargetName2', etc.
Might work with ProjectName as well

Xcode4 Linking Problem. File was built for archive which is not the architecture being linked (arm6)

Recently, I switched to Xcode4 and when I compile my project I got following error.
ld: warning: ignoring file /Users/myname/Library/Developer/Xcode/DerivedData/appname-hezrgyqimckztgbdlslkavphdclw/Build/Products/Debug-iphoneos/libTapkuLibrary.a, file was built for archive which is not the architecture being linked (armv6)
Undefined symbols for architecture armv6:
"_OBJC_CLASS_$_TKLoadingView", referenced from:
objc-class-ref in RootViewController.o
I opened the TapkuLibrary and checked that it's Architectures set to 'Standard (armv6 armv7)'.
What can I do to fix this problem?
I figured out what caused the problem. I changed 'Build Active Architecture Only' of TapkuLibrary from Yes to No and it compiles with no problem.
I was able to solve this problem by doing the opposite of the accepted answer - I changed the 'Build Active Architecture Only' from NO to YES.
Had the same problem. But the reason was different I suppose. I was using the library.a file built for simulator and trying to run it on device.. came to know that i need different .a files for simulator and device. I hope this helps someone ;)
I met this problem when I upgraded the XCode to 4.5 and iOS to iOS6. For GMGridView, it just happened.
Not for simulator, but only for device.
I fixed this by the following steps:
1) Go to GMGridView project -> Build Settings
2) Under Setting -> Architectures, select "Standard (armv7, armv7s)"
Then clean all (including DerivedData) and rebuild.
Hope it helps!
Try to remove the armv6 architecture, and compile it only for armv7.
Something else that worked for me was making sure that all sub projects had the architecture set to be armv6 and armv7, making sure to set both the TARGET and the PROJECT of each sub project. After cleaning and rebuilding everything, it worked without a problem.
This solved the problem for me:
Some external library like three20 did extra settings for
Build Settings->Architectures->Any iOS SDK
the value is "armv6 armv7" that different from standard "armv7 armv7s"
drop down and select "Standard", it worked for me.
I managed it by clicking the "unfriendly" Project's (in my case GMGridView).
In tab "Architectures", I changed the value from something (I don't remember exactely anymore, I guess it was:) "armv7, armv6s" to "armv7, armv7".
After that it worked for me.
I managed to resolve this by just creating a adhoc configuration inside the Tapku info settings ...
XCODE 4, Project > Archive = library not found for -lTapkuLibrary - Issues - devinross/tapkulibrary - GitHub
Make sure the build variants on your projects are set to "normal".
If you are building a project which includes other projects, take a look inside the DerivedData folder for the main project. Examine the archive files with the "lipo -info yourarchive.a". Also, examine the timestamps on these archives. You may find that these libraries are not getting rebuilt or you are trying to link against an old version of the archive which is the wrong architecture.
In my case, I shutdown Xcode and deleted the DerivedData folder for my main project. This forced a full rebuild when I reopened the main project in Xcode 4. The full rebuild caused the i386 archives to be created (or the correct version to be found) & the simulator version to link correctly.
This worked for me :
Click on the offending framework's 'Project' file (xcodeproj).
Go to the "Info" tab for the framework's 'Project' (not 'Target').
Expand 'Configurations' and make sure that both 'Debug' and 'Release' have 2 configurations set--one for the framework's 'Project' and another for the framework's 'Target'. In the case of frameworks the 'Target' compiles to a Library and not an application, so it's easy to get confused.
'Debug' should have the Project set to 'Debug' and the Library set to 'Shared'
'Release' should have the Project set to 'Release' and the Library set to 'Shared'
Compile, run, and enjoy.
If you ended up mangling your entire project trying to figure this out, then you might want to double-check your Application's Project build phases (as Gon suggested). The Library should be there highlighted in red, even if it doesn't exist on your drive. If not, as long as it's set to 'Shared' you should be able to add it back again.
If you really really really mangled your project, then you may be forced to blow out your DerivedData folder, as russes suggested. Also, check the 'Organizer', since Xcode has a way of saving crap all over the place.
Oh, and you checked to make sure that 'armv6' is there right? :)
If I get the ignore file warning - I would run lipo -info on ignored file to find it's architecture as below
lipo -info libTapkuLibrary.a
That would print either of i386, armv6, armv7, armv7s, x86_64 etc. In general, that architecture has to match with your target build platform. E.g.
i386 = ios simulator or 32 bit build on mac os x
armv6 armv7 arm7s = ios device
x86_64 = 64 bit build on mac os x
Depending on the mismatch, either you have to rebuild your library for your target platform or change your target platform.
Note: For fat binaries, lipo -info will print a combination of above architectures.
I fixed this problem thanks to another thread where they show that armv6/armv7 is actually a little different than what you think it is: Upgrading to xcode 4 error No architectures to compile for
None of these answers worked for me. (Similar warning message, different static library project). For me it was having configured XCode to honor the build directories of the targets and then having targets build in a local build/ directory that caused the problem. Configuring XCOde to use "Derived data" folder fixed it.
I had this problem with the Three20 library. The thing that finally did it for me was switching the Project Format from Xcode 3.1 to Xcode 3.2 - leaving 'build active arch only' as "no".
I tried all the options above and none worked.
This is the right answer:
simply dragging a framework in your project won't link it properly (or something along these lines, in any case)
what you need to do is select the framework you want to add in Build Phases (click on your project's blue icon, then select your project's name under Targets, then the tab Build Phases), see here for more reference.
Had the same problem, and tried diverse solutions from the page to no avail.
I still had a message telling me my library was not build for arm64.
Finally how I resolved it :
opened the project.pbxproj for the library in a text editor
searched for VALID_ARCHS
there were 4 occurrences, 2 of which did not contain arm64
I manually added arm64 in the chain (VALID_ARCHS = "arm64 i386 armv7 armv7s")
rebuild the lib and it was all right
Seems sometimes the build settings displayed by XCode is incomplete, and doesn't correspond precisely to the make file.