<div dir="ltr">I was afraid it will come to that :) I will try to make something tonight, either it will help you fix it, or I will find out what I did wrong</div><div class="gmail_extra"><br><div class="gmail_quote">On 8 October 2017 at 09:49, Daniel Dunbar <span dir="ltr">&lt;<a href="mailto:daniel_dunbar@apple.com" target="_blank">daniel_dunbar@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Is it possible for you to make a small test package that shows the problem, and file a bug in <a href="http://bugs.swift.org" target="_blank">bugs.swift.org</a>? There may be something we need to fix in SwiftPM before this can work (because of our linking model).<span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888"> - Daniel</font></span><div><div class="h5"><br><div><br><blockquote type="cite"><div>On Oct 7, 2017, at 10:42 PM, Ján Kosa via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-6734854148308687225Apple-interchange-newline"><div><div dir="ltr">That is exactly what I did. The only package that depends on the protobuf is the PluginInterface. Both MyPlugin and and PluginConsumer depend on the PluginInterface and not on the protobuf itself. I had to shuffle around my dependencies a bit, which resulted in smaller number of dependencies but they don&#39;t make much sense now (as in, some target had to depend on PluginInterface even if they don&#39;t need to, just to get access to protobuf). I could live with that if it solved the issue, but it didn&#39;t.<div><br></div><div>I am adding my Package.swift files in case I missed something:</div><div><br></div><div>PluginInterface:</div><div><br></div><div>```swift</div><div><span class="m_-6734854148308687225gmail-s1" style="font-family:Menlo;font-size:11px">let</span><span style="font-family:Menlo;font-size:11px"> package = Package(</span></div><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s2"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>name: </span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225gmail-s2">,</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>products: [ .library(name: <span class="m_-6734854148308687225gmail-s3">&quot;PluginInterface&quot;</span>, type: .dynamic, targets: [<span class="m_-6734854148308687225gmail-s3">&quot;PluginInterface&quot;</span>]) ],</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>dependencies: [ <span class="m_-6734854148308687225gmail-s2">.package(url: </span>&quot;<a href="https://github.com/apple/swift-protobuf.git" target="_blank">https://github.com/apple/<wbr>swift-protobuf.git</a>&quot;<span class="m_-6734854148308687225gmail-s2">, from: </span>&quot;0.0.0&quot;<span class="m_-6734854148308687225gmail-s2">) </span>],</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>targets: [ .target(name: <span class="m_-6734854148308687225gmail-s3">&quot;PluginInterface&quot;</span>, dependencies: [<span class="m_-6734854148308687225gmail-s3">&quot;SwiftProtobuf&quot;</span>]) ]</p><p class="m_-6734854148308687225gmail-p1">)```</p><p class="m_-6734854148308687225gmail-p1"><br></p><p class="m_-6734854148308687225gmail-p1">MyPlugin:</p><p class="m_-6734854148308687225gmail-p1">```swift</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-s1">let</span> package = <span class="m_-6734854148308687225gmail-s2">Package</span>(</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>name: </span>&quot;MyPlugin&quot;<span class="m_-6734854148308687225gmail-s3">,</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>products: [ .<span class="m_-6734854148308687225gmail-s4">library</span>(name: <span class="m_-6734854148308687225gmail-s5">&quot;MyPlugin&quot;</span>, type: .<span class="m_-6734854148308687225gmail-s4">dynamic</span>, targets: [<span class="m_-6734854148308687225gmail-s5">&quot;PluginImpl&quot;</span>]) ],</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>dependencies: [</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3">.</span><span class="m_-6734854148308687225gmail-s4">package</span><span class="m_-6734854148308687225gmail-s3">(url: </span>&quot;path/to/PluginInterface.git&quot;<span class="m_-6734854148308687225gmail-s3">, from: </span>&quot;0.0.0&quot;<span class="m_-6734854148308687225gmail-s3">),</span><br></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>],</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>targets: [</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;PluginImpl&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;ProtoBufMessages&quot;<span class="m_-6734854148308687225gmail-s3">]),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;ProtoBufMessages&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225gmail-s3">])</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>]</p><div>


















<br class="m_-6734854148308687225webkit-block-placeholder"></div><p class="m_-6734854148308687225gmail-p1">)```</p><p class="m_-6734854148308687225gmail-p1"><br></p><p class="m_-6734854148308687225gmail-p1">PluginConsumer:</p><p class="m_-6734854148308687225gmail-p1">```swift</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-s1">let</span> package = <span class="m_-6734854148308687225gmail-s2">Package</span>(</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>name: </span>&quot;PluginConsumer&quot;<span class="m_-6734854148308687225gmail-s3">,</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>dependencies: [</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">package</span><span class="m_-6734854148308687225gmail-s3">(url: </span>&quot;<a href="https://github.com/PerfectlySoft/Perfect-WebSockets.git" target="_blank">https://github.com/<wbr>PerfectlySoft/Perfect-<wbr>WebSockets.git</a>&quot;<span class="m_-6734854148308687225gmail-s3">, from: </span>&quot;3.0.0&quot;<span class="m_-6734854148308687225gmail-s3">),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">package</span><span class="m_-6734854148308687225gmail-s3">(url: </span>&quot;<a href="https://github.com/PerfectlySoft/Perfect-HTTPServer.git" target="_blank">https://github.com/<wbr>PerfectlySoft/Perfect-<wbr>HTTPServer.git</a>&quot;<span class="m_-6734854148308687225gmail-s3">, from: </span>&quot;3.0.0&quot;<span class="m_-6734854148308687225gmail-s3">),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3">.</span><span class="m_-6734854148308687225gmail-s4">package</span><span class="m_-6734854148308687225gmail-s3">(url: </span>&quot;path/to/PluginInterface&quot;<span class="m_-6734854148308687225gmail-s3">, from: </span>&quot;0.0.0&quot;<span class="m_-6734854148308687225gmail-s3">),</span><br></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">package</span><span class="m_-6734854148308687225gmail-s3">(url: </span>&quot;<a href="https://github.com/krzyzanowskim/CryptoSwift.git" target="_blank">https://github.com/<wbr>krzyzanowskim/CryptoSwift.git</a>&quot;<span class="m_-6734854148308687225gmail-s3"><wbr>, from: </span>&quot;0.0.0&quot;<span class="m_-6734854148308687225gmail-s3">)</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>],</p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>targets: [</p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;AppMaster&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;Shared&quot;<span class="m_-6734854148308687225gmail-s3">, </span>&quot;CryptoSwift&quot;<span class="m_-6734854148308687225gmail-s3">]),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;PluginConsumer&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;Shared&quot;<span class="m_-6734854148308687225gmail-s3">, </span>&quot;CryptoSwift&quot;<span class="m_-6734854148308687225gmail-s3">]),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;Shared&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;ProtoBufMessages&quot;<span class="m_-6734854148308687225gmail-s3">, </span>&quot;PerfectHTTPServer&quot;<span class="m_-6734854148308687225gmail-s3">, </span>&quot;PerfectWebSockets&quot;<span class="m_-6734854148308687225gmail-s3">]),</span></p><p class="m_-6734854148308687225gmail-p2"><span class="m_-6734854148308687225gmail-s3"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>.</span><span class="m_-6734854148308687225gmail-s4">target</span><span class="m_-6734854148308687225gmail-s3">(name: </span>&quot;ProtoBufMessages&quot;<span class="m_-6734854148308687225gmail-s3">, dependencies: [</span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225gmail-s3">])</span></p><p class="m_-6734854148308687225gmail-p1"><span class="m_-6734854148308687225gmail-Apple-tab-span">        </span>]</p><div>






















<br class="m_-6734854148308687225webkit-block-placeholder"></div><p class="m_-6734854148308687225gmail-p1">)```</p><p class="m_-6734854148308687225gmail-p1"><br></p><p class="m_-6734854148308687225gmail-p1">App master is separate executable that shares some functionality with PluginConsumer, but it doesn&#39;t link against it in any way. I guess it could be omitted, but I wanted to give you whole thing as it is</p></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 October 2017 at 18:33, Geordie Jay <span dir="ltr">&lt;<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><div class="gmail_quote"><span><div dir="auto">Ján Kosa &lt;<a href="mailto:lopenka@gmail.com" target="_blank">lopenka@gmail.com</a>&gt; schrieb am Sa. 7. Okt. 2017 um 15:27:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I tried to use <span style="font-size:12.8px">@_exported and it helped somewhat. While I still have same warnings, size of the PluginInterface library went down by 6mb (to 120kb) so it looks like Protobuf is no longer statically linked to it. However, size of PluginConsumer executable went up by same 6mb, it looks like it is linked there twice now. </span></div></blockquote><div dir="auto"><br></div></span><div dir="auto">To be clear: take protobuf out of the PluginConsumer dependencies. Actually, I’m not sure which is which, but protobuf should only be listed as a dependency of one package, where it is imported as @_exported. After that, your other modules depend on the package that imports / exports protobuf.</div><div><div class="m_-6734854148308687225h5"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><span style="font-size:12.8px"></span><div><span style="font-size:12.8px">I also noticed interesting thing. If I build executable using `swift build` the size is around 17mb, when I generate xcode project and build it using that, size is around 200kb, but I get same warnings using both approaches</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 7 October 2017 at 15:44, Geordie Jay <span>&lt;<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><div class="gmail_quote"><span><div dir="auto">Ján Kosa &lt;<a href="mailto:lopenka@gmail.com" target="_blank">lopenka@gmail.com</a>&gt; schrieb am Sa. 7. Okt. 2017 um 13:34:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I tried swift package clean, but it didn&#39;t help</div><div><div><br></div><div>&quot;<span style="font-size:12.8px">Try to ensure the plugin provider module (libA) is (only) being compiled into its standalone shared library file.&quot; </span></div></div><div><div><span style="font-size:12.8px">How do I go about this? It is 3rd party module, it doesn&#39;t define any products (<a href="https://github.com/apple/swift-protobuf.git" target="_blank">https://github.com/apple/swif<wbr>t-protobuf.git</a>). Is there something I can do in my Package files to make sure it is loaded dynamically?</span></div></div></blockquote><div dir="auto"><br></div></span><div dir="auto">When you compile a package depending on protobuf, all the relevant symbols end up in your package’s library file. So here’s something you might try:</div><div dir="auto"><br></div><div dir="auto">import protobuf into your own “PluginProvider” module (package), which has a shared library product like this: ‘@_exported import Protobuf’ in some compiled swift file. Then from the other dependent modules “import PluginProvider” - the protobuf symbols should be available, and all from one (nonconflicting) source.</div><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">Geordie</div></font></span><div><div class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138h5"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><span style="font-size:12.8px"></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 October 2017 at 22:52, Geordie Jay <span>&lt;<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="auto">I think SwiftPM is (incorrectly) compiling <a href="http://a.xyz/" target="_blank">A.XYZ</a> into each of the modules that depend on it, as well as into your intended libA.so file.</div><div dir="auto"><br></div><div dir="auto">Try to ensure the plugin provider module (libA) is (only) being compiled into its standalone shared library file. Try cleaning the swiftpm build for one (swift package clean) and ensure the Package.swift files are correctly set up to output the shared library.</div><div dir="auto"><br></div><div dir="auto">Sorry I can’t be more specific, I’ve had these same kinds of issues before but I’m not 100% what they were.</div><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">Geordie</div></font></span><div><div class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554h5"><div dir="auto"><br></div><br><div class="gmail_quote"><div>Ján Kosa via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; schrieb am Fr. 6. Okt. 2017 um 14:41:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>It worked! Took me a while to iron out details, but it is working now. Huge thanks sir, I will name my firstborn after you.<div>Thanks for the <span style="font-size:12.8px">@_cdecl(&quot;initializePlugin&quot;<wbr>) tip as well, I didn&#39;t know about it and it will be very useful.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I am having slightly related problem now (it was there before, but I ignored it for the time being), not sure if I should start a new thread?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The PluginInterface module has one external dependency on module A, PluginConsumer has the dependency on module B which has dependency on same module A that the PluginInterface uses. When I load the plugin library, I get bunch of errors like:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Class <a href="http://a.xyz/" target="_blank">A.XYZ</a> is implemented in both libPluginInterface.dylib and libMyPlugin.dylib</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I know why it is there, but I don&#39;t know how to get rid of it. I can&#39;t just remove dependency from PluginConsumer and use the one from PluginInterface (if that would even work?) because PluginConsumer does not depend on it directly, but it is going through module B first</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Cheers,</span></div><div><span style="font-size:12.8px">Lope</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 4 October 2017 at 22:17, Daniel Dunbar <span>&lt;<a href="mailto:daniel_dunbar@apple.com" target="_blank">daniel_dunbar@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">The way that I have done this in the past is pass a protocol as an unsafe pointer to an exposed entry point:<div>```swift</div><div>            let entryPoint = dlsym(handle, “initializePlugin”)</div><div>            guard entryPoint != nil else {</div><div>                fatalError(&quot;missing plugin entry point: \(pluginPath)&quot;)</div><div>            }</div><div>            typealias PluginInitializationFunc = @convention(c) (UnsafeRawPointer) -&gt; ()</div><div>            let f = unsafeBitCast(entryPoint, to: PluginInitializationFunc.self)</div><div>            f(Unmanaged.passUnretained(sel<wbr>f).toOpaque())</div><div>```</div><div><br></div><div>and then in the plugin convert back to the appropriate type:</div><div><br></div><div>```</div><div><div>@_cdecl(&quot;initializePlugin&quot;)</div><div>public func initializePlugin(_ ptr: UnsafeRawPointer) {</div><div>    let manager = Unmanaged&lt;PluginManager&gt;.fromO<wbr>paque(ptr).takeUnretainedValue<wbr>()</div><div>```</div><div><br></div><div>HTH,</div><div> - Daniel</div><div><br><blockquote type="cite"><div><div class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901h5"><div>On Oct 4, 2017, at 11:02 AM, Ján Kosa via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761Apple-interchange-newline"></div></div><div><div><div class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901h5"><div>Hello folks,<div><br></div><div>I have been toying with dynamic libraries, trying to implement plugin functionality. I was able to get to the point where I can call simple function in loaded library, but I am having troubles starting more sophisticated communication channel.</div><div><br></div><div>There are 3 projects<br></div><div>- PluginConsumer is an app that loads plugin libraries </div><div>- MyPlugin is a plugin implementation, output is dynamic library that PluginConsumer loads</div><div>- PluginInterface is common interface that both MyPlugin and PluginConsumer use, so that they know how to communicate</div><div><br></div><div>My first idea was to have PluginInterface be a simple SPM project with single file where the bare-bones PluginInterface class would be:</div><div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"><br></span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">open</span> <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">class</span> PluginInterface {</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">    open func sayHi()</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift file:</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">// swift-tools-version:4.0</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = Package(</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    name: </span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">,</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    products: [ .library(name: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">&quot;PluginInterface&quot;</span>, type: .dynamic, targets: [<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">&quot;PluginInterface&quot;</span>]) ],</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    targets: [ <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">.target(name: </span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">) </span>]</p><div>




















<br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">UserPlugin is also very simple project containing only one file:</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">public</span> <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">func</span> getPlugin() -&gt; <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">AnyObject</span> {</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    return</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"> </span>MyPlugin<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">()</span></p><div>









<br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">class MyPlugin: PluginInterface {</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">    override func sayHi() {</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">        print(&quot;Hi from my plugin&quot;)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">    }</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift:</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">// swift-tools-version:4.0</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">Package</span>(</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    name: </span>&quot;MyPlugin&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">,</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    products: [ .<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">library</span>(name: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;MyPlugin&quot;</span>, type: .<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dynamic</span>, targets: [<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;MyPlugin&quot;</span>]) ],</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    dependencies: [ .<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">package</span>(url: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;url_to_PluginInterface&quot;</span>, from: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;0.0.0&quot;</span>), ],</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    targets: [</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>        .</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">target</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">(name: </span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">, dependencies: [</span>&quot;PluginInterface&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">]),</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>        .<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">target</span>(name: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;MyPlugin&quot;</span>, dependencies: [<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">&quot;PluginInterface&quot;</span>]),</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    ]</p><div>




















<br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">The PluginConsumer is bit more complicated, but here is relevant part (lib loading and function calling):</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">typealias</span> <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">I</span>nitFunction = <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">@convention</span>(c) () -&gt; <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">AnyObject</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> openRes = <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlopen</span>(<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">p</span>athToLib, <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_NOW</span>|<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_LOCAL</span>)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">i</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">f</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> </span>openRes<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> != </span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span>    defer<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p5"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span>        dlclose<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    }</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p6"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    let</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> symbolName = </span>&quot;mangled_symbol_name&quot;<br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    let</span> sym = <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlsym</span>(<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span>, symbolName)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    if</span> sym != <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span> {</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">        let</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> f: </span>InitFunction<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> = </span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">unsafeBitCast</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(sym, to: </span>InitFunction<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">.</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">self</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">        let</span> plugin = f() as? PluginInterface</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    }</p><div>






















<br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift file:</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">// swift-tools-version:4.0</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">Package</span>(</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    name: <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">&quot;PluginConsumer&quot;</span>,</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    dependencies: [ <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">.</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">package</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">(url: </span>&quot;path_to_plugin_interface&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">, from: </span>&quot;0.0.0&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">) </span>],</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    targets: [ <span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">.</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">target</span><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">(name: </span>&quot;PluginConsumer&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">, dependencies: [</span>&quot;PluginConsumer&quot;<span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">]) </span>]</p><div>


























<br class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">This all compiles nicely, MyPlugin project creates dylib file that executable created by PluginConsumer can load, but the problem is with following line:</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> plugin = f() as? PluginInterface<br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Type of the plugin is MyPlugin, but from the consumer&#39;s view, it doesn&#39;t inherit from PluginInterface so I can&#39;t call sayHi() method. I assume this is because there is no relation between PluginInterface class that compiler uses for MyPlugin project one that it uses for PluginConsumer project. After library is loaded, they are two completely different classes that happen to share same name. Is my assumption correct and how do I go about fixing it?</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">I had an idea I could make PluginInterface emit dynamic library that would be dynamically linked by both MyPlugin and PluginConsumer, thus making them share same PluginInterface class, but I can&#39;t figure out how to do that (or if it&#39;s right way of doing this).<br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Any help appreciated :)</p><p class="m_-6734854148308687225m_-4294955562354230567m_8729161781951157138m_8602944998557321586m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Lope</p></div></div></div></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailma<wbr>n/listinfo/swift-users</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>