<div><br><div class="gmail_quote"><div dir="auto">Ján Kosa &lt;<a href="mailto:lopenka@gmail.com">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/swift-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><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><div dir="auto"><br></div><div dir="auto">Geordie</div><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_3476204009829642554HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">Geordie</div></font></span><div><div class="m_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;) 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(self).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;.fromOpaque(ptr).takeUnretainedValue()</div><div>```</div><div><br></div><div>HTH,</div><div> - Daniel</div><div><br><blockquote type="cite"><div><div class="m_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_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761Apple-interchange-newline"></div></div><div><div><div class="m_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_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"><br></span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">open</span> <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">class</span> PluginInterface {</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">    open func sayHi()</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift file:</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">// swift-tools-version:4.0</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = Package(</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    name: </span>&quot;PluginInterface&quot;<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">,</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    products: [ .library(name: <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">&quot;PluginInterface&quot;</span>, type: .dynamic, targets: [<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">&quot;PluginInterface&quot;</span>]) ],</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    targets: [ <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">.target(name: </span>&quot;PluginInterface&quot;<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">) </span>]</p><div>




















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









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




















<br class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_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_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">typealias</span> <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">I</span>nitFunction = <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">@convention</span>(c) () -&gt; <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">AnyObject</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> openRes = <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlopen</span>(<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">p</span>athToLib, <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_NOW</span>|<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_LOCAL</span>)</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">i</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">f</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> </span>openRes<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> != </span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span>    defer<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p5"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span>        dlclose<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    }</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p6"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    let</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> symbolName = </span>&quot;mangled_symbol_name&quot;<br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    let</span> sym = <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlsym</span>(<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span>, symbolName)</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">    if</span> sym != <span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span> {</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">        let</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> f: </span>InitFunction<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> = </span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">unsafeBitCast</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(sym, to: </span>InitFunction<span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">.</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">self</span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">        let</span> plugin = f() as? PluginInterface</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span>    }</p><div>






















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


























<br class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_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_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> plugin = f() as? PluginInterface<br></p><p class="m_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_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_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Any help appreciated :)</p><p class="m_3476204009829642554m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Lope</p></div></div></div></div>
_______________________________________________<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/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
_______________________________________________<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/mailman/listinfo/swift-users</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div>
</blockquote></div></div>