iosxcode

After upgrading from Xcode 14.0 to Xcode 16.3, my SwiftUI project failed to run


Build succeed,but app startup failed. iOS Deployment Target is 15.0. Running on a device with iOS 17.0. C++ Language Dialect is set to GNU++20.

Error infomation

dyld[1669]: Symbol not found: ___cxa_current_primary_exception
  Referenced from: <9DF2FEE8-CDED-3A0C-8FFE-8C9FF289257D> /private/var/containers/Bundle/Application/434A154D-E917-4263-901D-B6E06E28DEF1/myapp.app/myapp.debug.dylib
  Expected in:     <BADF6383-4494-32F2-97EF-716EA17420F6> /usr/lib/libc++.1.dylib
Symbol not found: ___cxa_current_primary_exception
  Referenced from: <9DF2FEE8-CDED-3A0C-8FFE-8C9FF289257D> /private/var/containers/Bundle/Application/434A154D-E917-4263-901D-B6E06E28DEF1/myapp.app/myapp.debug.dylib
  Expected in:     <BADF6383-4494-32F2-97EF-716EA17420F6> /usr/lib/libc++.1.dylib
dyld config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/usr/lib/libLogRedirect.dylib:/usr/lib/libBacktraceRecording.dylib:/usr/lib/libMainThreadChecker.dylib:/usr/lib/libRPAC.dylib:/usr/lib/libViewDebuggerSupport.dylib
Message from debugger: Terminated due to signal 6

Here are a few solutions that I tried but none of them worked.

  1. Corrupted Build Cache / Derived Data (Very Common): Stale or inconsistent files from previous builds, especially after Xcode upgrades, can cause linker errors.

    Solution: Perform a thorough clean: In Xcode: Product > Clean Build Folder (or Shift+Cmd+K). Crucially: Delete Derived Data. Quit Xcode. Go to Xcode > Settings (or Preferences) > Locations. Click the small arrow next to the "Derived Data" path to open it in Finder. Delete the entire Derived Data folder (or at least the subfolder corresponding to your project). Restart Xcode and your iOS device. If using CocoaPods, navigate to your project directory in Terminal and run pod install again after deleting Derived Data. Try building and running again.

  2. Inconsistent Build Settings: Mismatches in build settings between your project, the main app target, and the target that produces yituart.debug.dylib (if it's separate) are frequent culprits.

    Solution: Verify consistency for all relevant targets (Project, App Target, yituart.debug.dylib target) and all configurations (Debug/Release): iOS Deployment Target: Ensure it's consistently 15.0 or lower everywhere. C++ Language Dialect: Ensure it's identically set to GNU++20 everywhere. Any mismatch (e.g., one target using C++14, another

  3. C++20) can cause linking errors. C++ Standard Library: Ensure it's set to libc++ everywhere. C++20 Dialect vs. Deployment Target: Using a newer standard like C++20 while targeting an older OS like iOS 15 can sometimes lead to build/link issues, even if the runtime OS (iOS 17) supports it well. The build process might create fragile links based on the older target SDK.

    Solution (Diagnostic Step): Temporarily change the C++ Language Dialect from GNU++20 to a more widely compatible standard like GNU++17 or GNU++14 across all relevant targets and configurations. Perform the thorough clean again (Clean Build Folder + Delete Derived Data). Rebuild and run. If the error disappears, it points to an incompatibility related to using C++20 features while targeting iOS 15. If the error persists, C++20 itself is less likely the direct cause.

  4. Dependency Issues (CocoaPods, etc.): Problems with how third-party libraries (Pods) are integrated or built.

    Solution: Ensure Pods are correctly installed. A clean reinstall might help:
    Close Xcode.
    In Terminal (in project directory): pod deintegrate
    rm Podfile.lock
    rm -rf Pods/
    rm -rf *.xcworkspace
    pod install
    Delete Derived Data again.
    Reopen the .xcworkspace file in Xcode and try building.


Solution

  • I had the same problem, I could only solve it by removing the -Objc flag from Other Linker Flags, which some cocoapods packages insert because it depends on libs .a, this flag causes it to import unused codes that cause this error to happen, with me the problem is with Google Mobile Ads that inserts this flag, but the curious thing is that this problem only happens with iOS devices that have iOS versions below 18.4, the iPhone 15 with 18.4 the problem does not happen, now with all devices with 18.3, 18.2 and even 15.2 the application does not open.

    Now the million dollar question, is the problem with Xcode or with third party libs that still depend on the -Objc flag?

    For now the only solution I found was:

    Downgrade XCode to 16.2

    Apple seems to be aware of it — they even mentioned a potential cause in this thread:
    šŸ‘‰ Apple Developer Forums – Linker behavior regression in iOS < 18.4