Uploaded image for project: 'Swift'
  1. Swift
  2. SR-14008

"Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib" issue for `swift test`

    XMLWordPrintable

    Details

      Description

      With development snapshot toolchains, swift build/swift run for executable/library targets importing _Differentiation has no problem.

      However, running swift test for test targets importing _Differentiation fails with a dynamic linker issue:

      $ swift test
      [7/7] Linking SwiftDifferentiationPackageTests
      
      * Build Completed!
      2020-12-30 14:28:23.465 xctest[20739:26994456] The bundle “SwiftDifferentiationPackageTests.xctest” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
      2020-12-30 14:28:23.465 xctest[20739:26994456] (dlopen_preflight(/Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests): Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib
        Referenced from: /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests
        Reason: image not found)
      

      Setting DYLD_LIBRARY_PATH to the toolchain library directory containing libswift_Differentiation.dylib does not help:

      $ DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a.xctoolchain/usr/lib/swift/macosx swift test
      2020-12-30 14:29:55.586 xctest[20925:26997481] The bundle “SwiftDifferentiationPackageTests.xctest” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
      2020-12-30 14:29:55.586 xctest[20925:26997481] (dlopen_preflight(/Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests): Library not loaded: /usr/lib/swift/libswift_Differentiation.dylib
        Referenced from: /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest/Contents/MacOS/SwiftDifferentiationPackageTests
        Reason: image not found)
      

      However, manually invoking the xctest command from swift test -v with DYLD_LIBRARY_PATH does work:

      $ DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-12-23-a.xctoolchain/usr/lib/swift/macosx /Applications/Xcode-beta12_3.app/Contents/Developer/usr/bin/xctest /Users/danielzheng/Differentiation/.build/x86_64-apple-macosx/debug/SwiftDifferentiationPackageTests.xctest
      Test Suite 'All tests' started at 2020-12-30 14:35:43.472
      Test Suite 'SwiftDifferentiationPackageTests.xctest' started at 2020-12-30 14:35:43.473
      Test Suite 'DifferentiationTests' started at 2020-12-30 14:35:43.473
      Test Case '-[DifferentiationTests.DifferentiationTests testExample]' started.
      Test Case '-[DifferentiationTests.DifferentiationTests testExample]' passed (0.112 seconds).
      Test Suite 'DifferentiationTests' passed at 2020-12-30 14:35:43.585.
      	 Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.112) seconds
      Test Suite 'SwiftDifferentiationPackageTests.xctest' passed at 2020-12-30 14:35:43.585.
      	 Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.112) seconds
      Test Suite 'All tests' passed at 2020-12-30 14:35:43.585.
      	 Executed 1 test, with 0 failures (0 unexpected) in 0.112 (0.113) seconds
      

      Maybe this is because swift test does not pass the DYLD_LIBRARY_PATH environment variable to the xctest invocation?

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            danzheng Dan Zheng
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated: