<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I’m learning about Swift on Linux and using modules to wrap C libraries. &nbsp;One of the things I wanted to do was use libdispatch with blocks from Swift. &nbsp;I thought it would be easy to use a module to wrap &lt;dispatch/dispatch.h&gt;.<div class=""><br class=""></div><div class="">I made a module called “CDispatch” with a module.modulemap like this</div><div class=""><br class=""></div><div class="">=======</div><div class=""><div class="">module CDispatch [system] {</div><div class="">&nbsp; &nbsp; header "/usr/include/dispatch/dispatch.h"</div><div class="">&nbsp; &nbsp; export *</div><div class="">&nbsp; &nbsp; link "dispatch"</div><div class="">}</div></div><div class="">========</div><div class=""><br class=""></div><div class="">Then I created a little demo project called gcd4 whose Source/main.swift prints some things and then uses a dispatch queue and a block to print a message after 2 seconds delay.</div><div class=""><br class=""></div><div class="">=========</div><div class=""><div class="">CDispatch.dispatch_after(time, queue, {</div><div class="">&nbsp; &nbsp; print("Delayed!")</div><div class="">})</div></div><div class="">========</div><div class=""><br class=""></div><div class="">The entire project is checked in at&nbsp;<a href="https://github.com/sheffler/gcd4" class="">https://github.com/sheffler/gcd4</a></div><div class="">and the CDispatch module is checked in at&nbsp;<a href="https://github.com/sheffler/CDispatch" class="">https://github.com/sheffler/CDispatch</a></div><div class=""><br class=""></div><div class="">If I try to “swift build” the project, it almost works but reports that dispatch_after is not found. &nbsp;It seems that this function is not defined if the “blocks" feature is not provided at compilation time.</div><div class=""><br class=""></div><div class="">========</div><div class=""><div class="">Compiling Swift Module 'gcd4' (1 sources)</div><div class="">/home/sheffler/swift/gcd4/Sources/main.swift:42:1: error: module 'CDispatch' has no member named 'dispatch_after'</div><div class="">CDispatch.dispatch_after(time, queue, {</div><div class="">^~~~~~~~~ ~~~~~~~~~~~~~~</div><div class="">&lt;unknown&gt;:0: error: build had 1 command failures</div><div class="">swift-build: exit(1): ["/home/sheffler/src/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swift-build-tool", "-f", "/home/sheffler/swift/gcd4/.build/debug/gcd4.o/llbuild.yaml”]</div></div><div class="">========</div><div class=""><br class=""></div><div class="">I got the demo program to work by first using “swift build” to retrieve the CDispatch module, and then manually running the compiler like this (and including the “-Xcc -fblocks” arguments)</div><div class=""><br class=""></div><div class="">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</div><div class=""><br class=""></div><div class="">This is all pretty neat! &nbsp;I’ve got blocks, dispatch queues and ARC on Ubuntu. &nbsp;I have one question and one remark.</div><div class=""><br class=""></div><div class="">- Am i missing something about how to create the CDispatch module? &nbsp;Why can’t “swift build” build this?</div><div class=""><br class=""></div><div class="">- Creating Git repositories for simple modules that wrap a single library and include a header file or two seems like too much. &nbsp;I would love to have been able to create a sub-directory in my project with a modulemap that includes &lt;dispatch/dispatch.h&gt; and links libdispatch.so</div><div class=""><br class=""></div><div class="">Thanks</div><div class="">Tom</div><div class=""><br class=""></div><div class="">P.S. - I tried to make this easy to check out and compile</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>