Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift in Linux: use of unresolved identifier 'dispatch_async'

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'

like image 296
zig1375 Avatar asked Oct 18 '22 18:10

zig1375


1 Answers

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.

like image 58
Brad Larson Avatar answered Nov 04 '22 01:11

Brad Larson