简体   繁体   English

在 Mac 上使用 CFBundleCreate 在 C++ 中加载动态共享库 (DLL)

[英]Load a dynamic shared library (DLL) on Mac in C++ using CFBundleCreate

How do I implement a function to load a dll(aka framework) on Mac OS using C++?如何使用 function 在 Mac OS 上使用 C++ 加载 dll(又名框架)?
void LoadFramework(const char* frameworkPath) { //frameworkPath is the absolute path of the framework }

Edit:编辑:
When I google searched for this problem, I mostly ended up with dlopen solution to load the framework.当我用谷歌搜索这个问题时,我大多以 dlopen 解决方案来加载框架。 What I am instead looking for is to use CFBundleCreate to load the framework.我正在寻找的是使用CFBundleCreate来加载框架。 It seems to me that there are a bunch of methods needed to be called to construct an URL from const char * path.在我看来,需要调用一堆方法来从 const char * 路径构造一个 URL 。 I found the needed code in pieces, and could not write one comprehensive solution.我找到了需要的代码,无法编写一个全面的解决方案。

It typically is just a few lines of straightforward code to open a framework in Mac, something along the lines of:在 Mac 中打开框架通常只需几行简单的代码,大致如下:

bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
    CFSTR("/System/Library/Frameworks/<your_framework_name.framework>"),
    kCFURLPOSIXPathStyle, true);

bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
assert(bundle != NULL);

and pretty much everything in that snippet is well documented.该片段中的几乎所有内容都有据可查。 I would suggest adding more detail in the question, as to the specifics of what exactly is not working for you.我建议在问题中添加更多详细信息,以了解哪些具体不适合您。

Why not do this?为什么不这样做?

using DLL_Namespace;

This should give you access to the DLL.这应该可以让您访问 DLL。

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

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