Skip to content
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

Failed to load dynamic library on Windows 10 when running an example 0.0.7 #22

Closed
pouryaomidi opened this issue Feb 12, 2021 · 9 comments

Comments

@pouryaomidi
Copy link

pouryaomidi commented Feb 12, 2021

Hi, Running the example given on https://pub.dev/packages/dart_serial_port/example gives me the following error:

Invalid argument(s): Failed to load dynamic library (126)
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)
#2 LibraryLoader.load (package:dart_serial_port/src/dylib.dart:78:58)
#3 dylib (package:dart_serial_port/src/dylib.dart:31:67)
#4 _SerialPortImpl.availablePorts. (package:dart_serial_port/src/port.dart:230:32)
#5 Util.call (package:dart_serial_port/src/util.dart:37:21)
#6 _SerialPortImpl.availablePorts (package:dart_serial_port/src/port.dart:230:21)
#7 SerialPort.availablePorts (package:dart_serial_port/src/port.dart:82:61)
#8 main (file:///D:/Projects/playground/untitled/bin/untitled.dart:14:33)
#9 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19)
#10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I am using dart sdk version: 2.12.0-259.8.beta (beta) (Tue Feb 2 15:59:29 2021 +0100) on "windows_x64".

Any tip is appreciated!

Pourya

@jpnurmi
Copy link
Owner

jpnurmi commented Feb 12, 2021

Could you check the instructions at #7? In short, flutter_serial_port ships the required external library.

@pouryaomidi
Copy link
Author

Hi @jpnurmi , Thanks for your response. Are you suggesting that on Windows there is no way to use the serialport using purely dart?

@jpnurmi
Copy link
Owner

jpnurmi commented Feb 13, 2021

@pouryaomidi It's certainly possible to use dart_serial_port without Flutter, but libserialport.dll needs to be present. All flutter_serial_port does is to build and deploy the DLL for you [*], but you can build and deploy the DLL by hand instead.

[*] Simply because Flutter provides a build system to do that, whereas pure Dart packages don't have a way to build native C code.

@pouryaomidi
Copy link
Author

@jpnurmi, I've already built libserialport using Visual Studio, then added the library in my path, but I still face the same issue mentioned above. Should I mention the libserialport.dll anywhere in the yaml file?

@jpnurmi
Copy link
Owner

jpnurmi commented Feb 13, 2021

Where is the DLL placed? If I remember correctly, in Windows the DLL can be found "out of the box" if it's in the same directory with the application executable. If that's not possible, you can also define the LIBSERIALPORT_PATH environment variable to tell dart_serial_port where to lookup the DLL.

@pouryaomidi
Copy link
Author

I have tried to put it in dart/bin and next to the example file and both results in failed to load error. I will try the last option you said and send an update.

@pouryaomidi
Copy link
Author

After creating a system environment variable LIBSERIALPORT_PATH as it is specified in your code in dylib.dart, I was able to run the code. Thanks for helping!

@jpnurmi jpnurmi closed this as completed Feb 13, 2021
@mohammad-imanni
Copy link

@jpnurmi, I've already built libserialport using Visual Studio, then added the library in my path, but I still face the same issue mentioned above. Should I mention the libserialport.dll anywhere in the yaml file?

Give me built tutorial of libserialport

@dkozenkov
Copy link

dkozenkov commented Jun 2, 2023

Give me built tutorial of libserialport

@blackghost1379, you can get the compiled library "libserialport-0.dll" here:
https://packages.msys2.org/package/mingw-w64-x86_64-libserialport?repo=mingw64
Then make changes to the dylib.dart.

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

No branches or pull requests

4 participants