tensorflow / swift

Swift for TensorFlow
https://tensorflow.org/swift
Apache License 2.0
6.13k stars 608 forks source link

dyld: Symbol not found: _$sSly7ElementQz5IndexQzcigTq #177

Closed maxvol closed 4 years ago

maxvol commented 5 years ago

On Mojave, Xcode 10.2, Toolchain 0.3 getting this result for a command-line macOS app -

dyld: Symbol not found: _$sSly7ElementQz5IndexQzcigTq
  Referenced from: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3-a.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib
  Expected in: /usr/lib/swift/libswiftCore.dylib
 in /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3-a.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib

I configured the project as described here - https://stackoverflow.com/questions/55782961/swift-for-tensorflow-dyld-symbol-not-found-ssly7elementqz5indexqzcigtq

Roslund commented 5 years ago

I have the same issue.

dan-zheng commented 5 years ago

Could someone please share a simple reproducer?

Roslund commented 5 years ago

I'm not sure how to reproduce. But From what I've figured out, It seems like the problem is that in Xcode 10.2, Xcode uses the version of the swift standard library that's installed on the system, which differs from swift for TensorFlow standard library.

It works fine in Xcode 10.1 and in the Terminal.

lukegeorge85 commented 5 years ago

On Mojave, Xcode 10.2, Toolchain 0.3 getting this result for a command-line macOS app -

dyld: Symbol not found: _$sSly7ElementQz5IndexQzcigTq
  Referenced from: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3-a.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib
  Expected in: /usr/lib/swift/libswiftCore.dylib
 in /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3-a.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib

I configured the project as described here - https://stackoverflow.com/questions/55782961/swift-for-tensorflow-dyld-symbol-not-found-ssly7elementqz5indexqzcigtq

I'm the poster of the original question. Any update on this issue? Is there any additional info I can provide to assist?

hfoffani commented 5 years ago

Same here. Mojave 10.14.4, Xcode 10.2.1, Toolchain 0.3.1 Minimal steps to reproduce it:

  1. install Toolchain as indicated following steps 1,2,3 and 4.
  2. file new project - macos-application-command line tool
  3. name the project - create.
  4. change project to legacy building
  5. modify main.swift to add some code:
    import TensorFlow
    let t : Tensor<Float> = [[1,2],[3,4]]

    (code completion for Tensor type works so the framework is recognized)

  6. builds OK
  7. run fails:
    dyld: Library not loaded: @rpath/libswiftPython.dylib
    Referenced from: /Users/hernan/Library/Developer/Xcode/DerivedData/swift-t6-abxqyqiwnjnmhzfhehvbfsxkaccz/Build/Products/Debug/swift-t6
    Reason: image not found
    Program ended with exit code: 9
  8. add runpath search paths: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3.1.xctoolchain/usr/lib/swift/macosx
  9. builds OK
  10. now run fails with:
    dyld: Symbol not found: _$sSly7ElementQz5IndexQzcigTq
    Referenced from: /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3.1.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib
    Expected in: /usr/lib/swift/libswiftCore.dylib
    in /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.3.1.xctoolchain/usr/lib/swift/macosx/libswiftPython.dylib
    Program ended with exit code: 9

I assume it's picking up the standard libswiftCore.dylib instead of the Toolchain's one.

maxvol commented 5 years ago

Reproducible with either a macOS playground or a macOS app, also from toolchain from 30 April and Xcode 10.2.1

F20170604 commented 5 years ago

I was having the same issue, so I downgraded my Xcode to 10.0 version. Everything is working absolutely fine in that.

yeatse commented 5 years ago

Adding a Run Script in Build Phases temporarily fixes this issue:

install_name_tool -delete_rpath /usr/lib/swift $TARGET_BUILD_DIR/$PRODUCT_NAME || true
image

This script forces generated executable load the Swift version specified in Build Settings -> Runpath Search Paths instead of the one built in latest Xcode.

hfoffani commented 5 years ago

Thanks @Yeatse. Your workaround fixed the problem in the steps I mentioned before.

Adding a Run Script in Build Phases temporarily fixes this issue:

install_name_tool -delete_rpath /usr/lib/swift $TARGET_BUILD_DIR/$PRODUCT_NAME || true
dhasl002 commented 5 years ago

Adding a Run Script in Build Phases temporarily fixes this issue:

install_name_tool -delete_rpath /usr/lib/swift $TARGET_BUILD_DIR/$PRODUCT_NAME || true

Unfortunately, this does not work for me on Xcode 10.2.1

This is the error I get

error: install_name_tool: can't open file: /Users/dhaslam/Library/Developer/Xcode/DerivedData/Swift4Tensorflow-djrxnkrfydcxuicsyntnenxqidsq/Build/Products/Debug/Swift4Tensorflow (No such file or directory)
Command /bin/sh emitted errors but did not return a nonzero exit code to indicate failure

This folder does not exist: /Users/dhaslam/Library/Developer/Xcode/DerivedData/Swift4Tensorflow-djrxnkrfydcxuicsyntnenxqidsq/Build/

Any help would be great. I would like to avoid changing my Xcode version. Thanks!

ProfFan commented 4 years ago

@dan-zheng Can confirm that this is also happening with the Jupyter environment on macOS as well. I am on XCode 11.2.

/usr/lib/swift slip in somewhere, but not in the compiled libraries...

EDIT: Can work around by using DYLD_LIBRARY_PATH=${SWIFT_TOOLCHAIN_PATH}/usr/lib/swift/macosx, but then I got EXC_BAD_ACCESS for library calls...

amit-k-gupta commented 4 years ago

Hi @dan-zheng I tried to add the above run script as suggested by you, but unfortunately, it didn't work. I am using XCode 11.2.1(11B53). The build failed to compile and I got below errors

Screenshot 2019-12-26 at 11 42 49 AM
RahulBhalley commented 4 years ago

In Xcode, checkmark Signing & Capabilities > Hardened Runtime > Disable Library Validation under Target setting of your project. It resolved this problem for me & I hope it helps others too! Also I did not have to use run script.

Screen Shot 2019-12-29 at 11 15 55 AM

Solution was suggested by Daisuke in S4TF mailing list.

RahulBhalley commented 4 years ago

If someone is unable to find Hardened Runtime just simply add it by clicking + Capability & selecting it from the list.

RahulBhalley commented 4 years ago

@dan-zheng this seems to be a problem with code signing that prevents the S4TF program from running in Xcode. I feel that the solution should be documented in Installation readme to make it easy for Xcode users to get started with S4TF & not stay restricted to only REPL.

Edit: I've added a new PR regarding this.

amit-k-gupta commented 4 years ago

You guys can please answer the question here. As stackOverflow is accessed by almost every developer

https://stackoverflow.com/questions/59340366/cannot-import-tensorflow-in-swift-playground

Amit Kumar Gupta GMail amitgupta.lnct@gmail.com | Twitter https://twitter.com/Amit__G | LinkedIn https://www.linkedin.com/in/amitguptalnct/ Skype: amitgupta.lnct Ph. No:9164752648

On Mon, Dec 30, 2019 at 6:51 AM Rahul Bhalley notifications@github.com wrote:

@dan-zheng https://github.com/dan-zheng this seems to be a problem with code signing that prevents the S4TF program from running in Xcode. I feel that the solution should be documented in Installation readme to make it easy for Xcode users to get started with S4TF & not stay restricted to only REPL.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tensorflow/swift/issues/177?email_source=notifications&email_token=ABMBCXAFIXXKQ5QS5LH2D7TQ3FEKHA5CNFSM4HIE26QKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHZMWBY#issuecomment-569559815, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMBCXDRSH3R2SR5D7ZUYBLQ3FEKHANCNFSM4HIE26QA .

dan-zheng commented 4 years ago

I think the discussion is no longer related to the original issue dyld: Symbol not found: _$sSly7ElementQz5IndexQzcigTq, so I'll close this issue now.

If anyone encounters new issues, please create a new issue!