Swift on Linux: using the unresolved identifier 'dispatch_async'

I compiled libdispatch . This code works:

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

But if I put this code at the end of the file:

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

There was an error:

use of unresolved identifier 'dispatch_async'

+5
source share
1 answer

As I noted above, this looks like the current limitation using the Swift package manager . It currently does not support the addition of appropriate compile-time parameters, such as those needed to support blocks as input 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 a sheffler in a 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 your module maps for libdispatch, so configure them to match where you actually placed these system module directories.

+3
source

Source: https://habr.com/ru/post/1240177/


All Articles