如何通过Xcode构建插件包括OpenCV库(或其他第三方库)以供Unity使用?

问题描述 投票:0回答:2

我知道Unity在运行时无法动态调用插件中的第三方库(非标准库)。因此,我们需要在构建之前在插件中包含一些静态库。但是,我不清楚如何设置我的Xcode项目,其中包括一些静态库和设置过程。

我试图找到一些讨论这个主题的资源或教程,但我发现tutorials使用的是Visual Studio,而不是Xcode。

有谁熟悉这个话题?

xcode unity3d bundle static-libraries static-linking
2个回答
0
投票

您可以从以下提供的链接获得所需的帮助 -

https://github.com/darshanpv/OpenCV4Unity

https://forum.unity.com/threads/building-opencv-plugin-for-mac-osx.623662/#post-4179892

如果您遇到任何问题,请试试并告诉我。只关注Mac OSX部分。


0
投票

最后,我尝试了这个方法并成功构建了包含另一个第三方库的.bundle,以便Unity使用。

让我以OpenCV库为例。

首先,单击project,您可以看到Build Setting按钮。单击它并修改Header Search PathsLibrary Search Paths。在我的情况下,我输入/usr/local/Cellar/opencv/3.4.3/include/**/usr/local/Cellar/opencv/3.4.3/lib/**,然后,点击targets并做同样的事情。

此外,我们需要在项目中添加OpenCV库,因为Unity在运行时无法动态调用插件中的第三方库。因此,您需要打包它们然后Xcode将自动生成框架。

所以,单击Build Phases按钮。现在,您可以在此页面中看到Link Binary With Libraries,然后单击+按钮并单击add other...。然后,转到OpenCV库路径

/usr/local/Cellar/opencv/3.4.3/lib(对于我的情况)

选择没有“pythonx.x”的所有文件。

现在,您应该在Xcode IDE中看到Frameworks列表,然后您可以进行一些测试并检查是否成功添加第三方库。

enter image description here

C ++:

int ProcessImage()
{
    cv::Mat test(10, 10, CV_8UC1);  //use opencv library
    return test.rows;   // should return 10
}

c ++标题

#include <opencv2/imgproc.hpp>
#include <stdio.h>

extern "C"
{
    int ProcessImage();
}

C#

[DllImport("test")]   /*the name of Plugin is Test*/
private static extern int ProcessImage();

Debug.Log(ProcessImage().ToString());

结果

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.