XCode 13.1: Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport - ios

My app was running perfectly without any errors or warnings yesterday. But when I tried to run it today, the build failed - I haven't changed anything in the code:
Undefined symbol: __swift_FORCE_LOAD_$_XCTestSwiftSupport
How to fix this, and why would something like this occur suddenly when it was working before?
And this is an issue I've been experiencing with XCode a lot lately. My code will be running smoothly without any errors, but then XCode will randomly start throwing errors when I relaunch it at a different time - without making any changes in the actual code.
I have included some photos and the full text of those photos:
InventoryApp 3 issues
Warning
Could not find or use auto-linked library 'XCTestSwiftSupport'
Could not find or use auto linked framework 'XCTest'
Error
Undefined symbol: __swift FORCE LOAD $ XCTestSwiftSupport
ld: warning: Could not find or use auto-linked library 'XCTestSwiftSupport'
ld: warning: Could not find or use auto-linked framework
'XCTest'
Undefined symbols for architecture arm64:
"__swift_FORCE_LOAD_$_XCTestSwiftSupport", referenced from:
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in Button.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in ViewModel.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in Inventory.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in AddView.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in ScannerView.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in RegisterView.o
__swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp in ContentView.o
...
(maybe you meant: __swift_FORCE_LOAD_$_XCTestSwiftSupport_$_inventoryApp)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This condition also occurs if you add
import XCTest
to a file in a non-test bundle.

I solved this error by navigation to target app settings > Build Phases > Link Binary With Libraries > add the linked library "XCTest.framework".
If afterwards your app starts crashing, aborting with the following errors:
dyld: Library not loaded: #rpath/XCTest.framework/Versions/A/XCTest
0_abort_with_payload
Then you can take a look at the suggestions on this thread: Xcode 5.0.2 dyld: Library not loaded: #rpath/XCTest.framework/Versions/A/XCTest
The solution that worked for me was:
Navigate to target app > Build Settings > Linking > Other Linker Flags > editing or adding -weak_framework "XCTest"

This error randomly started to occur on my Xcode project today. I changed the setting.
PROJECT -> Build Settings -> Build Options -> Enable Testing Search Paths
from No to Yes, and the build succeeded.
Edit:...
This setting is on by default if the project is created with a testing target included. In my case I believe I added the testing target later so this setting will have been false. Although, I can't say why it didn't break as soon as I added the testing target.
See:
https://xcodebuildsettings.com

None of the above worked for me. In my case, a couple of mock files were targeted to both the framework and unit testing bundle. I just unticked the framework one to get rid of this error on the inspector.

I solved this error by navigation to target app settings > Build Phases > Link Binary with Libraries > add the linked library "XCTest.framework".
The action above is totally the same as the solutions above, though the issue "Library not loaded" appeared raised.
I solved the "Library not loaded" issue by setting up the framework to be optional while linked library.
[enter image description here][1]
It works for me in Xcode 13.2.1.

Related

resolving link errors with ios workspace with static library

I've done this before, several years ago with Xcode 5 or 6. Now using Xcode 8 or 9, I seem to be missing someting.
No matter what I've done, when I try to build and link my project, I get the Linker message:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_MyClass", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is not a duplicate question. It is not an architecture issue.
None of the other results I've found on S-O or google resolve this issue.
I'm obviously missing some build settings, but cannot figure out which one(s).
Between build attempts I've cleaned the build folder, and deleted DerivedData. Quit and restarted Xcode. Created a new set of projects with a new workspace and walked through the steps outlined below.
I'm writing in objective-C for this project if that matters (I don't think it does)
My question is what did I forget?
What I did --
Create a project for my framework and static library
a) create the project for a cocoa-touch framework - let's call it mySDK which creates mySDK.framework
b) Add a target for a cocoa-touch static library - let's call it SDK which creates libSDK.a
c) optionally build both targets -- they build fine
d) close the project
Create a project for my application - myApp - then close the project
Create a workspace - myWorkspace -- and open the workspace
Drag both project files from #1 mySDK and #2 myApp into the workspace
Build the framework and static library (both build and create the targets successfully)
Add the static library to myApp
a) Select myApp and go to build phases
b) Open Link Binary with Libraries
c) Drag from the library build products libSDK.a into the link binaries pane, set to "Required"
The library now appears in the Frameworks group-area in the myApp
7) Select the myApp project and go to build-settings
Add to Header Search Paths = "$(SRCROOT)/../mySDK/mySDK"
This resolves compile errors in finding the headers
Now I ask, why do I need to do anything else, shouldn't Xcode figure the rest out?
Various solutions or tutorials I've reviewed suggest adding:
Other Linking Flags = -ObjC
Library Search Paths = $(BUILT_PRODUCTS_DIR)
Library Search Paths = "$(SRCROOT)/../mySDK"
Changing Skip Install from YES to NO
Installation Build Product Location = $(BUILT_PRODUCTS_DIR)
I've tried all of these in different combinations.
Once I added the library to myApp I see that the Frameworks/libSDK.a file changes from red to black when I build the library so something in the workspace/project knows I built the library and it sees it.
So why when I try build myApp, do I still see the liner error:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_MyClass", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Nothing I have done seems to clear that error. I am pulling my hair out trying to find a solution.
I have also checked that it is building all the appropriate architectures, confirmed it using 'lipo -info'
Xcode obviously knows about the library, why isn't it linking?
My app also compiled with no problem but would hit an error while linking to the static library. My library was based on C++.
I had 2 problems to fix in my case:
The headers lacked proper extern "C" declarations for C functions in a C++ file.
One .cpp file did not #include its matching header so the extern "C" would be properly applied to the compiled version.
The linker had issues because the compiler used a mangled name for the function due to the mistakes. Later confirmed this by looking in the .a file with a text editor. I found my function with "_Z11" prefixed and "v" suffixed.
There was another clue: the error was reporting the missing function name with an underscore at the front.
Undefined symbols for architecture arm64:
"_myCFunction", referenced from:
SwiftModule.swiftFunction () -> () in MySwiftClass.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

When building react-native app: undefined symbols for architecture gxx_personality_v0

I'm just following the react native docs to build an app to run on device or release it [1].
I'm encountering the following error, even on a freshly new react native app. The app runs just fine in the simulator.
Undefined symbols for architecture i386: "___gxx_personality_v0",
referenced from:
_RCTDefaultLogFunction_block_invoke in libReact.a(RCTLog.o)
_RCTFormatLog in libReact.a(RCTLog.o)
___RCTAddLogFunction_block_invoke in libReact.a(RCTLog.o)
_RCTPerformBlockWithLogFunction in libReact.a(RCTLog.o)
_RCTPerformBlockWithLogPrefix in libReact.a(RCTLog.o)
RCTGetLocalLogFunction() in libReact.a(RCTLog.o)
___RCTPerformBlockWithLogPrefix_block_invoke in libReact.a(RCTLog.o)
...
ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)
I'm basically doing
react-native init SampleApp
... generates app
react-native run-ios # works fine (on simulator)
react-native run-ios --configuration Release # fails with the error above.
It fails with the same if I open the XCode project, change the Scheme to Release, and try to build.
What's happening? Looks like I'm missing a library? How do I check it's there? (I'm new to both react native and iOS, so don't assume I know much :)
Thanks!
--
[1] https://facebook.github.io/react-native/docs/running-on-device.html
I had this exact error and solved it via these instructions:
I just fixed this by deleting and creating my scheme in Xcode (credit goes to this SO post). Here's what I did in Xcode 7.3.1:
Open your project in Xcode.
Click Product > Scheme > Manage Schemes.
Select the scheme for your project, then click the minus (—) near the
bottom left to delete it.
Now click the plus (+) to create a new scheme for your project.
That's all I had to do, hth :)

"directory not found for option '-L/..' " Cocoapods issue

I'm using the CocoaLumberjack library in my Xcode project. I'm running into an issue when updating to the latest (2.2.0) version via pod install. Attaching screen of the error I'm seeing. Error description reads:
ld: warning: directory not found for option '-L/$(PROJECT_DIR)/build/Debug-iphoneos'
Undefined symbols for architecture armv7:
"_ddLogLevel", referenced from:
(Various project files referencing 'ddLogLevel')
armv7 is supported as a valid architecture by my CocoaLumberjack target settings.
Tried the solution here https://stackoverflow.com/a/18618187/3347084 but after doing so I received a different compiler error ld: library not found for -lGoogleAnalyticsServices. Could not fix and decided not to go too far down that rabbit hole unless I'm sure it's necessary to fix my original issue.

Linking libiconv on ios

I am trying to use the objective-git library for an ios application I am in the proccess of developing. I am able to get the library to compile, link, and run perfectly fine in the simulator. However, when I try to run the application on an actual iPad, I get the followign error:
Undefined symbols for architecture armv7s:
"_libiconv", referenced from:
_git_path_iconv in libObjectiveGit-iOS.a(path.c.o)
"_libiconv_close", referenced from:
_git_path_iconv_clear in libObjectiveGit-iOS.a(path.c.o)
"_libiconv_open", referenced from:
_git_path_iconv_init_precompose in libObjectiveGit-iOS.a(path.c.o)
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe the issue is that I am compiling the libgit2 library with a different version of iconv then the one included with ios. However, I have messed with the build script in an attempt to force it to link with the ios version, but the error persists. How should I go about properly linking the iconv library so that I can run the application on an actual device?
You need to add libiconv.tbd to 'Link Binary With Libraries' section in Build Phases.
Note: I know ObjectiveGit fixed this issue but maybe that helps to others those who are trying to use iconv in their projects.

build error while add revmob ad in iOS app

I want to add RevMob add in my app but there are some errors
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SKStoreProductViewController", referenced from:
objc-class-ref in RevMobAds(RevMobStoreController.o)
"_SKStoreProductParameterITunesItemIdentifier", referenced from:
-[RevMobStoreController openStoreWithITunesItemId:] in RevMobAds(RevMobStoreController.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have added StoreKit,SystemConfiguration and RevMob Frameworks already.
I am using Xcode4.3 and ios4.2
Plz help me.
Thanks in advance.
You need to add the StoreKit framework
EDIT: I see now what you mean, there was an issue with the older versions, I'm adding a link to an edited framework to solve that issue: Edited Revmob Framework
You must link against StoreKit.framework
It looks like the ad sdk you have now does not include support for use with the simulator.
-[RevMobStoreController openStoreWithITunesItemId:] in RevMobAds(RevMobStoreController.o)
ld: symbol(s) not found for architecture i386
if you get anything that mentions "not found for architecture" means revmob didnt include classes for running on simulator. You have 2 choices. look for a missing library ".a file" or only compile for testing on a device.
I've ran into an issue with the new ios6 where revmob did not support the new iphone 5 armv7s architecture.
Double check your revmob installation or try compiling to your phone instead of the simulator
When your are dropping the files manually in xcode the files are not copied to Bundle. So "SKStoreProductViewController.m" was the file not copied in the bundle so the error occurred. To resolve the error. Drag the files only .m files to Copy Bundle Resourceas shown in the image
This error can also happen if you removed a file from your project and subsequently re-created it. Sometimes Xcode doesn't automatically re-include it in the 'compile sources' box (when you click on target).
Check the box and see if all of your source files are included, if not then drag them in and rebuild.
They release a new SDK version (4.6.0) that works perfectly on older Xcode versions!
This also happens with Appirater. I was getting this message:
Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_SKStoreProductViewController", referenced from: objc-class-ref in Appirater.o "_SKStoreProductParameterITunesItemIdentifier", referenced from: +[Appirater rateApp] in Appirater.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
---To Fix---
add StoreKit.framwork in --> BuildPhases
---Under-> Link Libraries with Libraries
If you have more than one target you might need to add the
StoreKit.framwork to both Targets.
I faced similar issue and after long search and checking sample RevMob code, i found this solution, may be help others:
Under project target, select Build Settings, under Deployment, check iOS Deployment Target, change the value to 'iOS 9.0' or higher.
I hope this help.

Resources