简体   繁体   English

我应该在OSX上使用CFPlugin还是dlopen()作为C ++的插件

[英]Should I use CFPlugin or dlopen() for plugin for C++ on OSX

I need to make a plugin library on OSX which shall be loaded at run time. 我需要在OSX上制作一个插件库,该插件库将在运行时加载。 The library is mostly in C++. 该库主要使用C ++。 The way plugin needs to behave is that the program will scan a directory and search for plugins. 插件的行为方式是该程序将扫描目录并搜索插件。 Now it needs to get some information from plugins (like type) and needs to create instance based on that. 现在,它需要从插件(如类型)中获取一些信息,并需要基于该信息创建实例。

I searched for options and got these two for OSX - dlopen() and CFPlugin . 我搜索了选项,并为OSX- dlopen()CFPlugin获得了这两个选项。 The advantage with dlopen() is that we don't need to extend our base abstract class (which we have to if we use CFPlugin ). dlopen()的优点是我们不需要扩展基本抽象类(如果使用CFPlugin ,则必须CFPlugin )。 The disadvantage is that we need to load the library before knowing its type. 缺点是我们需要在知道库类型之前加载库。

With CFPlugin , Apple has not clearly mentioned that is it loaded before we create its instance or not. 对于CFPlugin ,Apple并未明确提及是否在创建实例之前先将其加载。 We can call CFPlugInFindFactoriesForPlugInTypeInPlugIn function to know all the functions capable of creating instance. 我们可以调用CFPlugInFindFactoriesForPlugInTypeInPlugIn函数来了解所有能够创建实例的函数。 But is the plugin loaded before it searches for available functions? 但是在搜索可用功能之前是否已加载插件?

Finally going ahead with dlopen() to load the *.bundle plugin. 最后,使用dlopen()加载*.bundle插件。 Advantage of using bundle is that *.plist shall always be embedded in it and any information we need before loading the bundle can be obtained from the plist file. 使用捆绑软件的优势在于, *.plistplist必须始终嵌入其中,并且可以从plist文件中获取加载捆绑软件之前需要的任何信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM