Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Can't run in macOS SwiftUI App #602

Open
jonkan opened this issue Jan 30, 2021 · 4 comments
Open

Can't run in macOS SwiftUI App #602

jonkan opened this issue Jan 30, 2021 · 4 comments

Comments

@jonkan
Copy link

jonkan commented Jan 30, 2021

I'm encountering a runtime error if I try to use TensorFlow in an SwiftUI App:

dyld: Symbol not found: _$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.12.xctoolchain/usr/lib/swift/macosx/libswiftFoundation.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

Setup:

  • macOS 11.1
  • Xcode 12.4 and/or Xcode 12.2 Beta 3 (same issue)
  • Swift for TensorFlow 0.12 Release

Steps to reproduce:

  • Create a new project, chosing macOS and App. Leaving Interface and Life Cycle as default, i.e. SwiftUI.
  • Check the "Disable Library Validation"
  • If using Xcode 12.4, apply fix for "LLDB provided no error string" (#532)
  • Create a new file with the following:
import TensorFlow

func test() -> String {
    let x = Tensor<Float>([[1, 2], [3, 4]])
    return String(describing: x + x)
}
  • Run (no need to call the function)

Also, if choosing Command Line Tool instead of App, everything works as expected.

@porterchild
Copy link
Contributor

One thing you can try is to look at the arguments for a successful build, and try adding some of those arguments to the scheme of the unsuccessful build.

You can find the successful arguments by building as Command Line Tool (since that works), then going the the Report Navigator tab in Xcode, clicking on the build, then the "Export..." button at the top of the middle pane, which will give you all the build arguments. The export arguments might be interesting since you've got a dyld runtime linker issue. Maybe try pasting some of them in to Edit Scheme -> Arguments -> Environment Variables of your unsuccessful build.

I haven't seen that exact error before, but I've solved other dyld: Symbol not found errors with export DYLD_FRAMEWORK_PATH=path to my other built frameworks or export DYLD_LIBRARY_PATH=<path to toolchain>/usr/lib/swift/macosx/ depending on what Referenced from: and Expected in: said in the error.

@jonkan
Copy link
Author

jonkan commented Feb 2, 2021

Thank you for your tips. I wasn't able to get anywhere though..

The error seems to indicate that SwiftUI wants some symbol that's missing from tensorflow's libswiftFoundation.dylib. Then I would've expected to find it in the "default" libswiftFoundation.dylib. But grep:ing for the symbol (as suggested here) showed nothing, which is weird:
otool -tV /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/macosx/libswiftFoundation.dylib | grep '_$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF'
Not really sure that's the "default" libswiftFoundation.dylib though, but it was my best guess from find.

Even weirder, I do find the symbol in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/swift/libswiftFoundation.dylib

I did try setting DYLD_LIBRARY_PATH to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/macosx in the scheme environment variables, which gave me another error:

dyld: Symbol not found: _$s2os28getNullTerminatedUTF8Pointer_5usingSVSS_SpyypGSgztF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/macosx/libswiftos.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

But don't really know what's going on, or what I'm doing trying to troubleshoot this.. :P

It does seem to be some library version inconsistencies though. Found a post with a very similar issue and explanation in the swift forums. Can't really draw any conclusions from it though, is SwiftUI-support doomed?

@BradLarson
Copy link
Contributor

If you try to use a toolchain from Swift.org to build your application and ignore the TensorFlow bits for now, does that work? There may have been some significant changes between when we last had a successful macOS toolchain build and upstream Swift.

If a Swift.org toolchain works to build your application, that would narrow it down to something wrong in the 0.12 macOS toolchain, which was still using the custom tensorflow branch of the compiler.

@jonkan
Copy link
Author

jonkan commented Feb 2, 2021

Hmm, no..

Swift 5.3.3 Release

dyld: Symbol not found: _$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Library/Developer/Toolchains/swift-5.3.3-RELEASE.xctoolchain/usr/lib/swift/macosx/libswiftFoundation.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

Trunk Development (main)

dyld: Symbol not found: _$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-01-27-a.xctoolchain/usr/lib/swift/macosx/libswiftFoundation.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

Swift 5.4 Development

dyld: Symbol not found: _$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Library/Developer/Toolchains/swift-5.4-DEVELOPMENT-SNAPSHOT-2021-01-23-a.xctoolchain/usr/lib/swift/macosx/libswiftFoundation.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

Swift 5.3 Development

dyld: Symbol not found: _$sSo12NSFileHandleC10FoundationE9readToEndAC4DataVSgyKF
  Referenced from: /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI
  Expected in: /Library/Developer/Toolchains/swift-5.3-DEVELOPMENT-SNAPSHOT-2020-11-11-a.xctoolchain/usr/lib/swift/macosx/libswiftFoundation.dylib
 in /System/Library/Frameworks/SwiftUI.framework/Versions/A/SwiftUI

Edit:
Unchecking the "Disable Library Validation" does make it run for all of the above and the tensorflow 0.12 toolchain..??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants