0

I am having trouble utilising the libserialport.dart package. I have put a libserialport.so in the root of the project. When trying to run an application I get the following error:

Unhandled exception: Invalid argument(s): Failed to load dynamic library 'libserialport.so': libserialport.so: cannot open shared object file: No such file or directory

This tells me that the package is looking for the file somwhere else - but where?

The original library links the library this way, which results in it not finding the library:

LibSerialPort? _dylib;
LibSerialPort get dylib {
  return _dylib ??= LibSerialPort(ffi.DynamicLibrary.open(
    resolveDylibPath(
      'serialport',
      dartDefine: 'LIBSERIALPORT_PATH',
      environmentVariable: 'LIBSERIALPORT_PATH',
    ),
  ));
}

If I replicate the plugin locally, but changing the linking as such, the library works as expected:

var libraryPath =
    path.join(Directory.current.path, 'libserialport.so');

LibSerialPort? _dylib;
LibSerialPort get dylib {
  return _dylib ??= LibSerialPort(ffi.DynamicLibrary.open(libraryPath));
}

The question is: where to put the .so file so it would work with the original verison? Where does resolveDylibPath() link to?

If possible I would like to avoid using my modified version as that brings license implications I am not entirely sure how to deal with.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362

1 Answers1

0

Apparently the function looks for the path in the LIBSERIALPORT_PATH enviroment variable. Setting it to '.' made it work!

In the terminal:

export LIBSERIALPORT_PATH=.