5

I compiled libdispatch. This code is working:

import Dispatch
var lockQueue = dispatch_queue_create("com.test.async", nil);

But if I put this code to end file:

dispatch_async(lockQueue) {
    print("test1");
}

I got an error:

use of unresolved identifier 'dispatch_async'

4
  • 2
    What's the module map you're using to pull in libdispatch to Swift? Are you using the package manager? Commented Jan 8, 2016 at 15:46
  • I use official module: github.com/apple/swift-corelibs-libdispatch yes, first code block is working. import Dispatch and dispatch_queue_create working.
    – zig1375
    Commented Jan 8, 2016 at 15:47
  • 2
    This sounds related to this issue: bugs.swift.org/browse/SR-397 where any libdispatch function calls that need blocks aren't getting found. It sounds like the Swift Package Manager needs to be able to support custom compiler flags for modules for this to work. Commented Jan 8, 2016 at 15:52
  • I can reproduce: Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c) Target: x86_64-unknown-linux-gnu
    – JAL
    Commented Jan 8, 2016 at 15:55

1 Answer 1

3

As I commented above, this appears to be a current limitation with the Swift Package Manager. It doesn't currently support the addition of the appropriate compile-time options, such as the ones needed to support blocks as inputs to GCD functions (-Xcc -fblocks).

In the meantime, you can avoid the Swift Package Manager and compile your files directly using swiftc, with the appropriate options. An example is provided by sheffler in their test repository:

swiftc -v -o gcd4 Sources/main.swift -I .build/debug -j8 -Onone -g -Xcc -fblocks -Xcc -F-module-map=Packages/CDispatch-1.0.0/module.modulemap -I Packages/CDispatch-1.0.0 -I /usr/local/include

The -I options will pull in your module maps for libdispatch, so adjust those to match where you've actually placed these system module directories.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.