ashlar-code icon indicating copy to clipboard operation
ashlar-code copied to clipboard

rpath for libeditor_api.so not set correctly on Linux

Open maks opened this issue 3 years ago • 3 comments

Thanks for writing your editor from scratch article and for making and releasing this editor. I tried out the Linux release currently available (v0.1.0) but when attempting to run it from the bundle dir, as in: ./AshlarCode I get:

flutter: Editor
flutter: linux
flutter: Linux 5.13.0-35-generic #40-Ubuntu SMP Mon Mar 7 08:03:10 UTC 2022
flutter: 2.15.0 (stable) (Fri Dec 3 14:23:23 2021 +0100) on "linux_x64"
flutter: []
flutter: /home/maks/apps/Ashlar/bundle/AshlarCode
flutter: linux
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Invalid argument(s): Failed to load dynamic library './libeditor_api.so': libonigmolib.so: cannot open shared object file: No such file or directory
#0      _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:12)
#1      new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:23)
#2      nativeEditorApiLib (package:editor/native.dart:195)
#3      _git_init (package:editor/native.dart)
#4      git_init (package:editor/native.dart)
#5      main (package:editor/main.dart)
<asynchronous suspension>

so at a guess I think that libeditor_api is trying to dynamically link to libonigmolib but something is going wrong there even though that lib is in the same directory.

Then I noticed:

ldd libeditor_api.so 
	linux-vdso.so.1 (0x00007fff8673c000)
	libonigmolib.so => not found
	libgit2.so.28 => not found
	libssh2.so.1 => /lib/x86_64-linux-gnu/libssh2.so.1 (0x00007f91aee72000)
	libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f91aedda000)
	libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f91aeaff000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f91ae8e4000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f91ae800000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f91ae7e6000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f91ae5be000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f91ae5a2000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f91aefd5000)

so adding export LD_LIBRARY_PATH=. fixes the issue with linker finding libonigmolib, so you might want to pass r path when you are building libeditor_api to avoid this as the ld will not normally look in the cwd for libs.

But of course you are not shipping the version of libgit2 you linked to in your bundle and attempting to use the libgit2 I had installed just seg faults the app.

Since the app is closed source, I stopped debugging at this point.

maks avatar Mar 17 '22 00:03 maks

I actually recently wrote an article Porting C/C++ apps to Flutter mentioning this issue on Linux - of libraries not found, and how to address it. https://levelup.gitconnected.com/port-an-existing-c-c-app-to-flutter-with-dart-ffi-8dc401a69fd7

I will release the updated versions for desktop soon.

icedman avatar Mar 17 '22 01:03 icedman

Ah yes, good work on writing that article also, it was in fact via your FFI article that I discovered your work on the Flutter text editors.

And while I had read your article but I must admit I skimmed it a bit too quickly (as I have done a fair bit of Dart FFI myself previously) so I missed that you did include how to set the rpath in your example CMakeLists.txt. 👍🏻

maks avatar Mar 17 '22 02:03 maks

Thank you for pointing out rpath. I will have to look into that.

icedman avatar Mar 17 '22 09:03 icedman