<div dir="ltr">I tried swift package clean, but it didn't help<div><br></div><div>"<span style="font-size:12.8px">Try to ensure the plugin provider module (libA) is (only) being compiled into its standalone shared library file." </span></div><div><span style="font-size:12.8px">How do I go about this? It is 3rd party module, it doesn't define any products (<a href="https://github.com/apple/swift-protobuf.git">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><div class="gmail_extra"><br><div class="gmail_quote">On 6 October 2017 at 22:52, Geordie Jay <span dir="ltr"><<a href="mailto:geojay@gmail.com" target="_blank">geojay@gmail.com</a>></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="HOEnZb"><font color="#888888"><div dir="auto"><br></div><div dir="auto">Geordie</div></font></span><div><div class="h5"><div dir="auto"><br></div><br><div class="gmail_quote"><div>Ján Kosa via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> 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("initializePlugin"<wbr>) tip as well, I didn'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't know how to get rid of it. I can'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><<a href="mailto:daniel_dunbar@apple.com" target="_blank">daniel_dunbar@apple.com</a>></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("missing plugin entry point: \(pluginPath)")</div><div> }</div><div> typealias PluginInitializationFunc = @convention(c) (UnsafeRawPointer) -> ()</div><div> let f = unsafeBitCast(entryPoint, to: PluginInitializationFunc.self)</div><div> f(Unmanaged.passUnretained(<wbr>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("initializePlugin")</div><div>public func initializePlugin(_ ptr: UnsafeRawPointer) {</div><div> let manager = Unmanaged<PluginManager>.<wbr>fromOpaque(ptr).<wbr>takeUnretainedValue()</div><div>```</div><div><br></div><div>HTH,</div><div> - Daniel</div><div><br><blockquote type="cite"><div><div class="m_2109301194184823821m_5965118442678244901h5"><div>On Oct 4, 2017, at 11:02 AM, Ján Kosa via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761Apple-interchange-newline"></div></div><div><div><div class="m_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_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"><br></span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">open</span> <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">class</span> PluginInterface {</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"> open func sayHi()</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift file:</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">// swift-tools-version:4.0</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = Package(</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> name: </span>"PluginInterface"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">,</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> products: [ .library(name: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">"PluginInterface"</span>, type: .dynamic, targets: [<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">"PluginInterface"</span>]) ],</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> targets: [ <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">.target(name: </span>"PluginInterface"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">) </span>]</p><div>
<br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">UserPlugin is also very simple project containing only one file:</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">public</span> <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">func</span> getPlugin() -> <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">AnyObject</span> {</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> return</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"> </span>MyPlugin<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">()</span></p><div>
<br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">class MyPlugin: PluginInterface {</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"> override func sayHi() {</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"> print("Hi from my plugin")</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"> }</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift:</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2">// swift-tools-version:4.0</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">Package</span>(</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> name: </span>"MyPlugin"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">,</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> products: [ .<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">library</span>(name: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"MyPlugin"</span>, type: .<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dynamic</span>, targets: [<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"MyPlugin"</span>]) ],</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> dependencies: [ .<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">package</span>(url: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"url_to_PluginInterface"</span>, from: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"0.0.0"</span>), ],</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> targets: [</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> .</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">target</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">(name: </span>"PluginInterface"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">, dependencies: [</span>"PluginInterface"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">]),</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> .<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">target</span>(name: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"MyPlugin"</span>, dependencies: [<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">"PluginInterface"</span>]),</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> ]</p><div>
<br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">The PluginConsumer is bit more complicated, but here is relevant part (lib loading and function calling):</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">typealias</span> <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">I</span>nitFunction = <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">@convention</span>(c) () -> <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">AnyObject</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> openRes = <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlopen</span>(<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">p</span>athToLib, <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_NOW</span>|<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">RTLD_LOCAL</span>)</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">i</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">f</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> </span>openRes<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> != </span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p4"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span> defer<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> {</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p5"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span> dlclose<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> }</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p6"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> let</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> symbolName = </span>"mangled_symbol_name"<br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> let</span> sym = <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">dlsym</span>(<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s7">openRes</span>, symbolName)</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p2"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> if</span> sym != <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">nil</span> {</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> let</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> f: </span>InitFunction<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6"> = </span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">unsafeBitCast</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">(sym, to: </span>InitFunction<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">.</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">self</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s6">)</span></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1"> let</span> plugin = f() as? PluginInterface</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> }</p><div>
<br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">}</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">Package.swift file:</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p1">// swift-tools-version:4.0</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">import</span> PackageDescription</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> package = <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s2">Package</span>(</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> name: <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s3">"PluginConsumer"</span>,</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> dependencies: [ <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">.</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">package</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">(url: </span>"path_to_plugin_interface"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">, from: </span>"0.0.0"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">) </span>],</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-Apple-tab-span"></span> targets: [ <span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">.</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s5">target</span><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">(name: </span>"PluginConsumer"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">, dependencies: [</span>"PluginConsumer"<span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s4">]) </span>]</p><div>
<br class="m_2109301194184823821m_5965118442678244901m_1431573529807325761webkit-block-placeholder"></div><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">)</p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_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_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><span class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-s1">let</span> plugin = f() as? PluginInterface<br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Type of the plugin is MyPlugin, but from the consumer's view, it doesn't inherit from PluginInterface so I can'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_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't figure out how to do that (or if it's right way of doing this).<br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3"><br></p><p class="m_2109301194184823821m_5965118442678244901m_1431573529807325761gmail-p3">Any help appreciated :)</p><p class="m_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/<wbr>mailman/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/<wbr>mailman/listinfo/swift-users</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div>