我在Visual Studio 15中运行了一个包含一些OpenCV功能的C ++项目。我的目标是在Unity项目中执行该项目的方法。我已经看过编写本机插件和编组了,我得到了一个几乎空的C ++项目,它构建为.dll,并成功地在Unity中使用它来调用库的函数。
C#
public class Controller : MonoBehaviour {
[DllImport("DllName")]
private static extern int GetRandom();
void Start () {
print(GetRandom());
}
}
C ++
#include <iostream>
#define DllExport __declspec (dllexport)
extern "C" {
DllExport int GetRandom() {
return rand();
}
}
导致Unity日志打印一个随机数,因此基础工作。
我的问题是,如果我想使用OpenCV,我必须使用Cmake(GUI)来生成一个C ++项目,我无法构建一个可以使用的.dll。
我已将Configuration Properties->General->Project Defaults->Configuration Type
设置为.dll,但在构建时,它会显示Project not selected to build for this solution configuration
。
我已经读过我还必须在Configuration Manager中检查“部署”,但我认为这不是真的,因为在OpenCV项目中,以及在我的小项目中,两种情况下“部署”列显示为灰色且未选中。
我需要做什么,将OpenCV项目构建为.dll?可能它是我在cmake中的一些设置,或者也许它是Visual Studio中的内容,我想。