go-cshared-examples
go-cshared-examples copied to clipboard
Dart Example gives error with Dart 2.9.0-14.1.beta on MacOS
@dpurfield Thank you for giving Dart Example for FFI. But when I execute it, it gives the following errors.
Would really appreciate if you can help.
➜ ~ dart --version
Dart VM version: 2.9.0-14.1.beta (beta) (Tue Jun 9 10:52:57 2020 +0200) on "macos_x64"
$ dart client.dart
client.dart:5:23: Error: Expected 0 type arguments.
class GoSlice extends Struct<GoSlice> {
^
client.dart:35:24: Error: Expected 0 type arguments.
class GoString extends Struct<GoString> {
^
client.dart:22:35: Error: Type argument 'GoSlice' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
- 'GoSlice' is from 'client.dart'.
- 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
static Pointer<GoSlice> fromList(List<int> units) {
^
client.dart:49:38: Error: Type argument 'GoString' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
- 'GoString' is from 'client.dart'.
- 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
static Pointer<GoString> fromString(String string) {
^
client.dart:17:35: Error: The method 'load' isn't defined for the class 'Pointer<Int64>'.
- 'Pointer' is from 'dart:ffi'.
- 'Int64' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
units.add(data.elementAt(i).load<int>());
^^^^
client.dart:23:32: Error: Method not found: 'Pointer.allocate'.
final ptr = Pointer<Int64>.allocate(count: units.length);
^^^^^^^^
client.dart:27:44: Error: Method not found: 'Pointer.allocate'.
final GoSlice slice = Pointer<GoSlice>.allocate().load();
^^^^^^^^
client.dart:31:18: Error: The getter 'addressOf' isn't defined for the class 'GoSlice'.
- 'GoSlice' is from 'client.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
return slice.addressOf;
^^^^^^^^^
client.dart:44:37: Error: The method 'load' isn't defined for the class 'Pointer<Uint8>'.
- 'Pointer' is from 'dart:ffi'.
- 'Uint8' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
units.add(string.elementAt(i).load<int>());
^^^^
client.dart:51:32: Error: Method not found: 'Pointer.allocate'.
final ptr = Pointer<Uint8>.allocate(count: units.length);
Thanks, Satinder
I also tried codesign
command as referred here https://github.com/dart-lang/sdk/issues/38314#issuecomment-534102841, but that did not help either:
$ codesign --remove-signature awesome.so
$ dart client.dart
client.dart:5:23: Error: Expected 0 type arguments.
class GoSlice extends Struct<GoSlice> {
^
client.dart:35:24: Error: Expected 0 type arguments.
class GoString extends Struct<GoString> {
^
client.dart:22:35: Error: Type argument 'GoSlice' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
- 'GoSlice' is from 'client.dart'.
- 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
static Pointer<GoSlice> fromList(List<int> units) {
^
client.dart:49:38: Error: Type argument 'GoString' doesn't conform to the bound 'NativeType' of the type variable 'T' on 'Pointer' in the return type.
- 'GoString' is from 'client.dart'.
- 'NativeType' is from 'dart:ffi'.
Try changing type arguments so that they conform to the bounds.
static Pointer<GoString> fromString(String string) {
^
client.dart:17:35: Error: The method 'load' isn't defined for the class 'Pointer<Int64>'.
- 'Pointer' is from 'dart:ffi'.
- 'Int64' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
units.add(data.elementAt(i).load<int>());
^^^^
client.dart:23:32: Error: Method not found: 'Pointer.allocate'.
final ptr = Pointer<Int64>.allocate(count: units.length);
^^^^^^^^
client.dart:27:44: Error: Method not found: 'Pointer.allocate'.
final GoSlice slice = Pointer<GoSlice>.allocate().load();
^^^^^^^^
client.dart:31:18: Error: The getter 'addressOf' isn't defined for the class 'GoSlice'.
- 'GoSlice' is from 'client.dart'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
return slice.addressOf;
^^^^^^^^^
client.dart:44:37: Error: The method 'load' isn't defined for the class 'Pointer<Uint8>'.
- 'Pointer' is from 'dart:ffi'.
- 'Uint8' is from 'dart:ffi'.
Try correcting the name to the name of an existing method, or defining a method named 'load'.
units.add(string.elementAt(i).load<int>());
^^^^
client.dart:51:32: Error: Method not found: 'Pointer.allocate'.
final ptr = Pointer<Uint8>.allocate(count: units.length);
If it is fine with the maintainers, I can make a PR to fix the same