enwi / dartzmq

A simple dart zeromq implementation/wrapper around the libzmq C++ library
https://pub.dev/documentation/dartzmq/latest/
MIT License
26 stars 17 forks source link

Fails to load .so libary on linux desktop #8

Closed LordCommanderMay closed 2 years ago

LordCommanderMay commented 2 years ago
Launching lib/main.dart on Linux in debug mode...
Building Linux application...
Debug service listening on ws://127.0.0.1:37089/w-K6VIMgRmg=/ws
Syncing files to device Linux...
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Exception: Could not load any zeromq library
#0      ZContext._initBindings (package:dartzmq/src/zeromq.dart:77:7)
#1      new ZContext (package:dartzmq/src/zeromq.dart:66:5)
#2      main (package:remote_volume_control/main.dart:6:28)
#3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:130:25)
#4      _rootRun (dart:async/zone.dart:1426:13)
#5      _CustomZone.run (dart:async/zone.dart:1328:19)
#6      _runZoned (dart:async/zone.dart:1861:10)
#7      runZonedGuarded (dart:async/zone.dart:1849:12)
#8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:126:5)
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

[dartzmq] Failed to load library zmq:  Invalid argument(s): Failed to lookup symbol 'zmq_poller_new': /lib64/libzmq.so: undefined symbol: zmq_poller_new
[dartzmq] Failed to load library libzmq:  Invalid argument(s): Failed to load dynamic library 'liblibzmq.so': liblibzmq.so: cannot open shared object file: No such file or directory
[dartzmq] Failed to load library libzmq-v142-mt-4_3_5:  Invalid argument(s): Failed to load dynamic library 'liblibzmq-v142-mt-4_3_5.so': liblibzmq-v142-mt-4_3_5.so: cannot open shared object file: No such file or directory

--------------------------------------------------

sean@sean-fedora /lib64> ls | grep libzmq
libzmq.so
libzmq.so.5
libzmq.so.5.2.4

not entirely sure whats going on here the code is looking in the right place. any help would be appreciated

enwi commented 2 years ago

You need to either get a precompiled libzmq.so library or compile it youself and copy it into the build folder

LordCommanderMay commented 2 years ago

@enwi thanks for the quick response! I tried using the .so file from zmq fedora package and placed it next to the executable and the lib folder above it where I found another .so file for whatever reason running the 'flutter run' command deletes the so file in those locations. I also tried putting in just the build folder as you said. it does not delete it but still gives me the same error. I will next attempt to compile zmq myself but if you could be more specific about where .so library should go that would be very helpful thanks. Screenshot from 2022-07-19 12-45-23

enwi commented 2 years ago

I don't know the exact place for linux, but for windows it goes here build\windows\runner\Debug\. and build\windows\runner\Release\.. Is the build output structure similar on linux?

enwi commented 2 years ago

I remember that @ach-ee added some instructions for Linux, maybe these help:

Linux

Installing libzmq and running dart pub add dartzmq should be all that is required to use this package in your own application. To also run the example project, follow these steps:

  1. Install libzmq
  2. Install flutter (It may be easiest to install from source, otherwise you can follow the snap instructions)
  3. Update .profile with PATH to /flutter/bin (e.g. export PATH=$PATH:~/src/flutter/bin)
  4. Ensure ninja-build, clang, and libgtk-3-dev are installed (via apt or other package manager)
  5. Run flutter
  6. Run flutter config --enable-linux-desktop
  7. Clone this repo and cd dartzmq/example
  8. flutter create . to enable linux desktop for this project
  9. flutter run
  10. Click the "Send" button and the received message will be displayed as an array of ints [1,2,3,4,5]
LordCommanderMay commented 2 years ago

No luck with either of your suggestions unfortunately.

DynamicLibrary _dlOpenPlatformSpecific(final String name,
    {final String? path}) {
  String fullPath = _platformPath(name, path: path);
  return DynamicLibrary.open('/usr/local/lib/libzmq.so');
}

I replaced with the fullPath variable with the actual full path and I am getting a slightly different error.

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Exception: Could not load any zeromq library
#0      ZContext._initBindings (package:dartzmq/src/zeromq.dart:77:7)
#1      new ZContext (package:dartzmq/src/zeromq.dart:66:5)
#2      main (package:remote_volume_control/main.dart:6:28)
#3      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:130:25)
#4      _rootRun (dart:async/zone.dart:1426:13)
#5      _CustomZone.run (dart:async/zone.dart:1328:19)
#6      _runZoned (dart:async/zone.dart:1861:10)
#7      runZonedGuarded (dart:async/zone.dart:1849:12)
#8      _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:126:5)
#9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

[dartzmq] Failed to load library zmq:  Invalid argument(s): Failed to lookup symbol 'zmq_poller_new': /usr/local/lib/libzmq.so: undefined symbol: zmq_poller_new
[dartzmq] Failed to load library libzmq:  Invalid argument(s): Failed to lookup symbol 'zmq_poller_new': /usr/local/lib/libzmq.so: undefined symbol: zmq_poller_new
[dartzmq] Failed to load library libzmq-v142-mt-4_3_5:  Invalid argument(s): Failed to lookup symbol 'zmq_poller_new': /usr/local/lib/libzmq.so: undefined symbol: zmq_poller_new

any ideas? this .so was complied from the source code with cmake.

LordCommanderMay commented 2 years ago
sean@sean-fedora /u/l/lib> nm -D libzmq.so.5.2.5 | grep poll
                 U epoll_create1@GLIBC_2.9
                 U epoll_ctl@GLIBC_2.3.2
                 U epoll_wait@GLIBC_2.3.2
                 U poll@GLIBC_2.2.5
0000000000072010 T zmq_poll

zmq_poller_new is not exported on the Linux library

enwi commented 2 years ago

Then it can load the library, just that the version does not have support for zmq_poller

LordCommanderMay commented 2 years ago

sorry I ran the command wrong..

sean@sean-fedora /u/l/lib> nm libzmq.so.5.2.5 | grep zmq_poller_new
0000000000072df0 t _Z14zmq_poller_newv
0000000000019a9c t _Z14zmq_poller_newv.cold

I am a bit of a noob when it comes to c-shared Libraries. maybe the linux x86 exports it differently? I have no idea.

LordCommanderMay commented 2 years ago

After some research this seems to be more of a problem with how fedora/cmake version of zmq is complied so I'll close this

LordCommanderMay commented 2 years ago

Then it can load the library, just that the version does not have support for zmq_poller

Yes your right i remove all poller related variable and functions and it works