小编Xav*_*erB的帖子

我可以在 dart ffi 中调用 C++ 构造函数吗?

我是新来的菲。但我成功地将 dart-ffi 与函数调用一起使用。

现在,我想在 dart ffi 中使用 C++ 对象。我不知道这是否可能,但我尝试过这样的。

构造函数调用的原型是:

function_dart = lib
    .lookup<NativeFunction<function_native>>("constructor_function")
    .asFunction();
Run Code Online (Sandbox Code Playgroud)

但我有 : Failed to lookup symbol <constructor_function>,我尝试使用构造函数:

constructor_function
class::constructor_function
class::constructor_function(args)
Run Code Online (Sandbox Code Playgroud)

我做到了nm -gDC <lib>,我可以看到构造函数。

帮助 !

编辑1: @Botje,@Richard-Heap

我正在尝试使用 OpenCV 中的 VideoCapture 实例。

我已按照 Botje 的回答中的说明进行操作。

所以我创建了一个库,如下所示:

绑定.hpp:

#ifndef BIND_HPP
# define BIND_HPP

#include <opencv2/videoio.hpp>

extern "C" {
  cv::VideoCapture *cvCreateVideoCapture(char *filename, int apiPreference);
}
#endif
Run Code Online (Sandbox Code Playgroud)

绑定.cpp:

#include "bind.hpp"

cv::VideoCapture *createVideoCapture(char *filename, int apiPreference) {
  return new cv::VideoCapture(filename, apiPreference);
}
Run Code Online (Sandbox Code Playgroud)

我用来编译的命令:

g++ -c bind.cpp …
Run Code Online (Sandbox Code Playgroud)

c++ ffi dart flutter dart-ffi

3
推荐指数
1
解决办法
6712
查看次数

标签 统计

c++ ×1

dart ×1

dart-ffi ×1

ffi ×1

flutter ×1