3

I have an error message that I don't understand. I downloaded on the www.swift.org the swift toolchain 4.0.3 because I had an error message "Module compiled with Swift 4.0.3 cannot be imported by the Swift 4.2 compiler:"

Now, it makes me a different message:

CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (in target: CameraDemo)
    cd /Users/OlostA/Desktop/Git/r-d/CamBox
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk
    export TOOLCHAINS="org.swift.40320171205a "
    /Library/Developer/Toolchains/swift-4.0.3-RELEASE.xctoolchain/usr/bin/swiftc -incremental -module-name CameraDemo -Onone -enable-batch-mode -enforce-exclusivity=checked -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk -target arm64-apple-ios9.3 -g -module-cache-path /Users/OlostA/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -Xfrontend -serialize-debugging-options -enable-testing -index-store-path /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Index/DataStore -swift-version 4 -I /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos -F /Users/OlostA/Desktop/Git/r-d/framework/iphonesimulator -F . -F CameraDemo -F YI360Demo -F . -F CameraDemo -F YI360Demo -F . -F CameraDemo -F YI360Demo -F /Users/OlostA/Desktop/Git/r-d/CamBox/YICamera.framework -F /Users/OlostA/Desktop/Git/r-d/CamBox/SwiftyJSON.framework -F /Users/OlostA/Desktop/Git/r-d/CamBox/CocoaAsyncSocket.framework -F . -F CameraDemo -F YI360Demo -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/CocoaAsyncSocket.framework -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/YICamera.framework -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/CameraDemo.app -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/CameraDemo.swiftmodule -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/CameraDemo.app/Frameworks -F /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/CameraDemo.app/_CodeSignature -F /Users/OlostA/Desktop/Git/r-d/CamBox -c -j4 /Users/OlostA/Desktop/Git/r-d/CamBox/CameraDemo/ViewController.swift /Users/OlostA/Desktop/Git/r-d/CamBox/CameraDemo/AppDelegate.swift -output-file-map /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/Objects-normal/arm64/CameraDemo-OutputFileMap.json -parseable-output -serialize-diagnostics -emit-dependencies -emit-module -emit-module-path /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/Objects-normal/arm64/CameraDemo.swiftmodule -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/CameraDemo-generated-files.hmap -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/CameraDemo-own-target-headers.hmap -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/CameraDemo-all-target-headers.hmap -Xcc -iquote -Xcc /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/CameraDemo-project-headers.hmap -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Products/Debug-iphoneos/include -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/DerivedSources/arm64 -Xcc -I/Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/DerivedSources -Xcc -DDEBUG=1 -emit-objc-header -emit-objc-header-path /Users/OlostA/Library/Developer/Xcode/DerivedData/CameraDemo-atqalgbmsahmkqezdvsdizmgxtek/Build/Intermediates.noindex/CameraDemo.build/Debug-iphoneos/CameraDemo.build/Objects-normal/arm64/CameraDemo-Swift.h -Xcc -working-directory/Users/OlostA/Desktop/Git/r-d/CamBox

<unknown>:0: error: unknown argument: '-enable-batch-mode'
Command CompileSwiftSources failed with a nonzero exit code

May be I have to remove that arguments, but I don't know where to search...

Do you have any ideas?

Community
  • 1
  • 1
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • "Module compiled with Swift 4.0.3 cannot be imported by the Swift 4.2 compiler" means that you are trying to integrate some code compiled with the Swift 4.0.3 compiler into your new codebase, which will be compiled with Swift 4.2. So you "just" need to recompile the code/modules it complains about, with the newest version of Xcode. There is no need to install the old version of Swift (unless you actually want to use that of course :)) Are you using Carthage by any chance? – pbodsk Oct 25 '18 at 12:20
  • @pbodsk hi! I don't use Carthage... My problem is that it is code compiled by YItechnology (their framework in fact), I canno't compilate it. That's why I downloaded the swift 4.0.3 waiting their new framework... – ΩlostA Oct 25 '18 at 12:51
  • Ah, OK, just looked like the classic "I've updated to a new version of Swift and now it complains about old code" case. – pbodsk Oct 25 '18 at 13:14
  • I found this though: https://github.com/bazelbuild/rules_swift/issues/49 "Batch mode compilation was added to Swift 4.2", so you probably can't use it with Swift 4.0.3 – pbodsk Oct 25 '18 at 13:15
  • @pbodsk It seems we can disable it, but no success for me: https://stackoverflow.com/a/52481653/3581620 – ΩlostA Oct 25 '18 at 13:19

1 Answers1

4

TLDR

There is nothing you can do to fix the issue. Use Xcode 9 or update your codebase to Swift 5.


Full answer:

I encountered the same error, when using Xcode 10 with a Swift 4.0.3 toolchain, to build a project with a static library.

The issue here is as follows: because Xcode 10 operates on Swift 4.2, it composes a compile command for this specific Swift version. Specifically, it adds -enable-batch-mode flag, which optimizes build process. If you remove the flag by hand (e.g. pasting the whole command to Terminal app), it should succeed.

When you change the toolchain, Xcode itself is not smart enough to understand, that there is no such thing as -enable-batch-mode in 4.0.3.

Now, you could disable batch mode, and it should fix the issue, right? You do it in Build Settings, by adding new User-Defined Setting, SWIFT_ENABLE_BATCH_MODE with value NO.

But guess, what happens? Another unknown flag.

<unknown>:0: error: unknown argument: '-disable-batch-mode'
Command CompileSwiftSources failed with a nonzero exit code

Related questions:

Mateusz
  • 454
  • 4
  • 13
  • so what is the fix? I added it based on what you said, but still get same error – ikel Mar 21 '19 at 07:34
  • I ran into the problem, and with SWIFT_ENABLE_BATCH_MODE with set to NO, I also got `unknown argument: '-disable-batch-mode'`, did you end up fixing that error? – pledez May 29 '19 at 09:14
  • The thing is there is no fix for that. `SWIFT_ENABLE_BATCH_MODE: NO` was supposed to be THE fix, but instead of removing `-enable-batch-mode` flag, it replaces it with `-disable-batch-mode`, which is also unknown to Xcode. The only way to handle this is to use older version of Xcode or to recompile the library. Now that we have stable ABI in Swift 5, from now on this should not be an issue anymore. – Mateusz May 30 '19 at 10:56