Skip to content

primitive FFI sample broken on macOS due to import problem #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kakyoism opened this issue Mar 30, 2020 · 6 comments · Fixed by #44
Closed

primitive FFI sample broken on macOS due to import problem #42

kakyoism opened this issue Mar 30, 2020 · 6 comments · Fixed by #44

Comments

@kakyoism
Copy link

kakyoism commented Mar 30, 2020

Problem

On macOS, running the primitive sample code after proper CMaking the C lib gives the following error

$ !dart
dart primitives.dart
Unhandled exception:
Invalid argument(s): Failed to load dynamic library (dlopen(./primitives_library/libprimtives.dylib, 1): image not found)
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:10:55)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:19:12)
#2      main (file:///Users/kakyo/Desktop/_task/MMT/research/hello-mamguest/hello_dart/primitives/primitives.dart:41:32)
#3      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

Fix

$ sdiff -l theirs/ffi/primitives/primitives.dart mine/primitives/primitives.dart | cat -n | grep -v -e '($'
5	import 'dart:ffi';					      |	import 'dart:ffi' as ffi;
41	  final dylib = DynamicLibrary.open(path);		      |	  final dylib = ffi.DynamicLibrary.open(path);
@domesticmouse
Copy link
Member

Can you please submit the fix as a pull request?

@domesticmouse
Copy link
Member

Also, I'm curious how your change fixes things. Is there two different DynamicLibrary objects in scope?

@dcantir
Copy link
Contributor

dcantir commented Mar 31, 2020

@domesticmouse Hi, I got the same problem on my machine, but seems like the issue is using relative paths when trying to import the library (I get this message in the exception: "file system relative paths not allowed in hardened programs").

@dcharkes
Copy link
Contributor

"file system relative paths not allowed in hardened programs"

On MacOS the dylib needs to be in the same or a sub folder of the dart executable. See dart-lang/sdk#38314 (comment). (I'm not sure if you can fix the sample here, as the dart binary is part of the SDK folder and this simples repo is a different repo.)

@dcharkes
Copy link
Contributor

Also, I'm curious how your change fixes things. Is there two different DynamicLibrary objects in scope?

I did a breaking change, I changed those methods to be extension methods. Importing with as does not import the extension methods into the current scope.

@dcantir dcantir mentioned this issue Mar 31, 2020
@irvifa
Copy link

irvifa commented Apr 2, 2020

Hi I think the one proposed by @dcantir fix the problem and it's a minor one, can someone help take a look on that? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants