skip to Main Content

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

Photo

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)

Photo

5

Answers


  1. Chosen as BEST ANSWER

    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"


  2. This condition also occurs if you add

    import XCTest
    

    to a file in a non-test bundle.

    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
  5. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search