0

我想使用 dart FFI 从 dart 调用 ac 函数 test_main(int argc, char *argv[])。但是下面的代码显然不起作用,因为 Dart 字符串中不能有空字符。一个人如何在 dart 中编写 argv?

// FFI signature of the C function
typedef benchmark_hexagon_main_test = Int32 Function(Int32 argc, Pointer<Utf8> argv, Int32 len);
// Dart type definition for calling the C foreign function
typedef benchmarkHexagonMainTest = int Function(int argc, Pointer<Utf8> argv, int len);

  static Future<RunTime> benchmarkMainTest(String f, int P, int l) async {
    final DynamicLibrary libBenchmark = Platform.isAndroid
        ? DynamicLibrary.open("libbenchmark.so")
        : DynamicLibrary.process();
    final benchmarkHexagonMainTest hexagonBenchmark =
    libBenchmark
        .lookup<NativeFunction<benchmark_hexagon_main_test>>("benchmark_test_main_start")
        .asFunction();
    String strArgs = "Program" + null + " -f " + null  + f + null + " -P " + null  + "${P}" + null  +  " -l " + null  +"${l}" + null;
    hexagonBenchmark(7, Utf8.toUtf8(strArgs), strArgs.length);

  }
'''
4

0 回答 0