webview-bun icon indicating copy to clipboard operation
webview-bun copied to clipboard

ERR_DLOPEN_FAILED when launching compiled app

Open Auriosi opened this issue 10 months ago • 9 comments

Works fine when I run the script using bun run, but when I compile into an executable, it fails. I can't find a way to include the dll in the output either. Any ideas? Running Windows 11 on Bun 1.1.4. Using basic example but url set to Google.

Auriosi avatar Apr 17 '24 17:04 Auriosi

Yes, it's a known limitation of bun compile. You can't really include .dll files. It just bundles the source code and the package is trying to find the dll relative to it but it's not inside the bundle.

Though I had found a workaround long back and it still works. Because of this, I had always included another way to load dlls using WEBVIEW_PATH environment variable.

Extract the dll or just download from releases then inside a .env add that variable and the path then compile. It should work though the problem is that you'll need the dll file externally.

Im wondering if I can make this automatic, hence I'll be keeping this issue open.

tr1ckydev avatar Apr 17 '24 17:04 tr1ckydev

Worked, thanks! I feel like it's a little out of the scope of this project, but any idea on how/if it's possible to hide the terminal window? I don't trust the people who will be using this, and I won't always be around them to remind them to not close the terminal.

Auriosi avatar Apr 17 '24 20:04 Auriosi

Unfortunately there isn't any way yet to hide terminal unless bun fixes it or makes a way to do so.

tr1ckydev avatar Apr 18 '24 13:04 tr1ckydev

Worked, thanks! I feel like it's a little out of the scope of this project, but any idea on how/if it's possible to hide the terminal window? I don't trust the people who will be using this, and I won't always be around them to remind them to not close the terminal.

You can use editbin.exe from MSVC tools. The below powershell script will change the subsystem on an exe so the terminal will not show.

If you use Bun.spawn or node subprocess, "windowsHide" option is required to keep the terminal hidden.

$msvcPath = (& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find "VC\Tools\MSVC" | Get-ChildItem | Select-Object -First 1 -ExpandProperty FullName)
$editbin = Join-Path -Path $msvcPath -ChildPath "bin\Hostx64\x64\editbin.exe"

Start-Process -FilePath $editbin -ArgumentList "/subsystem:windows", "program-here.exe" -NoNewWindow -Wait

redraskal avatar Apr 20 '24 03:04 redraskal

vswhere was returning nothing, but I found editbin manually, ran from there. Thanks for your help!

Auriosi avatar Apr 20 '24 20:04 Auriosi

Bun 1.1.5 adds the ability to include .dll files in compile.

blaconix avatar Apr 22 '24 23:04 blaconix

Great! But I was thinking how about putting the dll in a common place so that it doesn't need to be embedded and multiple apps can use it. The binary size will then be significantly smaller.

Even better if it uses system installed bun instead of embedding bun in the binary.

tr1ckydev avatar Apr 23 '24 04:04 tr1ckydev

what to specify in the file for embedded dll? best regards

franklupo avatar May 06 '24 15:05 franklupo

what to specify in the file for embedded dll? best regards

if you wanted to embed a dll, you could do something like this:

import lib from "./libwebview.dll" with { type: "file" };
import { dlopen } from "bun:ffi";

const symbols = dlopen(lib, {
...
});

redraskal avatar May 06 '24 21:05 redraskal

Not sure if I'm missing something? Just booted a vanilla project with bun 1.1.9 and webview-bun 2.0.0, getting the following error,

23 |     case "linux": lib_path += "libwebview.so"; break;
24 |     case "darwin": lib_path += `libwebview.${process.arch}.dylib`; break;
25 |     default: throw "unsupported platform: " + process.platform;
26 | }
27 | 
28 | export const lib = dlopen(process.env.WEBVIEW_PATH ?? lib_path, {
                        ^
ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path.
 syscall: "dlopen"

      at bun:ffi:61:41
      at /home/aryzing/workspace/aryzing/explore-webview-bun/node_modules/webview-bun/src/ffi.ts:28:20

Bun v1.1.9 (Linux x64)

Inside the build folder, the package successfully created libwebview.so.

aryzing avatar May 22 '24 21:05 aryzing

~Embedding files through import attributes doesn't work when using dynamic import() function which is a bug in bun. Until then this issue will be kept open.~ UPDATE: It does work, if properly statically analyzable.

tr1ckydev avatar Jun 25 '24 10:06 tr1ckydev

Worked, thanks! I feel like it's a little out of the scope of this project, but any idea on how/if it's possible to hide the terminal window? I don't trust the people who will be using this, and I won't always be around them to remind them to not close the terminal.

You can use editbin.exe from MSVC tools. The below powershell script will change the subsystem on an exe so the terminal will not show.

If you use Bun.spawn or node subprocess, "windowsHide" option is required to keep the terminal hidden.

$msvcPath = (& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find "VC\Tools\MSVC" | Get-ChildItem | Select-Object -First 1 -ExpandProperty FullName)
$editbin = Join-Path -Path $msvcPath -ChildPath "bin\Hostx64\x64\editbin.exe"

Start-Process -FilePath $editbin -ArgumentList "/subsystem:windows", "program-here.exe" -NoNewWindow -Wait

Any ideas on how to edit exe but from a non Windows host? @redraskal

tr1ckydev avatar Jun 27 '24 02:06 tr1ckydev

Added support in latest release.

tr1ckydev avatar Jun 28 '24 20:06 tr1ckydev

Gave it a try and still seems there are some issues on the latest version: using Bun v1.1.17 and webview-bun 2.1.0,

34 |     }
35 | } else {
36 |     throw `unsupported platform: ${process.platform}-${process.arch}`;
37 | }
38 | 
39 | export const lib = dlopen(process.env.WEBVIEW_PATH ?? lib_file.default, {
                        ^
ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path.
 syscall: "dlopen"

      at bun:ffi:61:21
      at /home/user/app/node_modules/webview-bun/src/ffi.ts:39:20

Bun v1.1.17 (Linux x64)

aryzing avatar Jun 30 '24 15:06 aryzing

@aryzing There is probably some missing linked library in your system. Did you check the Linux instructions here?

tr1ckydev avatar Jun 30 '24 16:06 tr1ckydev

@tr1ckydev the both the dev and prod dependencies described there are installed on the machine returning the error above. Ubuntu 22.04.

Let me know if there's anything I can do to help debug

aryzing avatar Jul 01 '24 08:07 aryzing

@aryzing Can you cd to node_modules/webview-bun/build/ then run ldd libwebview.so and share the output?

tr1ckydev avatar Jul 03 '24 05:07 tr1ckydev

Sure, fairly large output

Details

$ ldd libwebview.so
./libwebview.so: /lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by ./libwebview.so)
        linux-vdso.so.1 (0x00007ffc38b92000)
        libgdk-3.so.0 => /lib/x86_64-linux-gnu/libgdk-3.so.0 (0x000071a8f226c000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x000071a8f2250000)
        libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x000071a8f2181000)
        libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x000071a8f216f000)
        libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x000071a8f2108000)
        libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x000071a8f20dc000)
        libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x000071a8f1fb4000)
        libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x000071a8f1fa8000)
        libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x000071a8f1f78000)
        libwebkit2gtk-4.0.so.37 => /lib/x86_64-linux-gnu/libwebkit2gtk-4.0.so.37 (0x000071a8ed400000)
        libgtk-3.so.0 => /lib/x86_64-linux-gnu/libgtk-3.so.0 (0x000071a8eca00000)
        libsoup-2.4.so.1 => /lib/x86_64-linux-gnu/libsoup-2.4.so.1 (0x000071a8ed363000)
        libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x000071a8f1f6f000)
        libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x000071a8ec826000)
        libjavascriptcoregtk-4.0.so.18 => /lib/x86_64-linux-gnu/libjavascriptcoregtk-4.0.so.18 (0x000071a8eaa00000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x000071a8ed229000)
        libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x000071a8f1f0f000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x000071a8ea600000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x000071a8ec73f000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x000071a8ec71f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000071a8ea200000)
        libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x000071a8ec6d5000)
        libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x000071a8f1f08000)
        libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x000071a8f1ef2000)
        libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x000071a8ec6c8000)
        libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x000071a8ec6bc000)
        libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x000071a8ec6b7000)
        libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x000071a8ec6b2000)
        libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x000071a8ec6aa000)
        libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x000071a8ea9b9000)
        libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x000071a8ec69e000)
        libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x000071a8ec699000)
        libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x000071a8ec688000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x000071a8ea879000)
        libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x000071a8ea864000)
        libepoxy.so.0 => /lib/x86_64-linux-gnu/libepoxy.so.0 (0x000071a8ea4cb000)
        libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x000071a8ea848000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x000071a8ea138000)
        libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x000071a8ea4a4000)
        libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x000071a8ea82d000)
        libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x000071a8ec679000)
        libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x000071a8ea08d000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x000071a8ea469000)
        libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x000071a8ea464000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x000071a8ea43a000)
        libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x000071a8ea42b000)
        libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x000071a8ea080000)
        libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x000071a8e9fff000)
        libicui18n.so.70 => /lib/x86_64-linux-gnu/libicui18n.so.70 (0x000071a8e9c00000)
        libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x000071a8e9f38000)
        libicuuc.so.70 => /lib/x86_64-linux-gnu/libicuuc.so.70 (0x000071a8e9a05000)
        libxml2.so.2 => /lib/x86_64-linux-gnu/libxml2.so.2 (0x000071a8e9823000)
        libsqlite3.so.0 => /lib/x86_64-linux-gnu/libsqlite3.so.0 (0x000071a8e96d6000)
        libxslt.so.1 => /lib/x86_64-linux-gnu/libxslt.so.1 (0x000071a8e9694000)
        liblcms2.so.2 => /lib/x86_64-linux-gnu/liblcms2.so.2 (0x000071a8e9632000)
        libwoff2dec.so.1.0.2 => /lib/x86_64-linux-gnu/libwoff2dec.so.1.0.2 (0x000071a8e9626000)
        libharfbuzz-icu.so.0 => /lib/x86_64-linux-gnu/libharfbuzz-icu.so.0 (0x000071a8e9f33000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x000071a8e94e8000)
        libgstallocators-1.0.so.0 => /lib/x86_64-linux-gnu/libgstallocators-1.0.so.0 (0x000071a8e94e1000)
        libgstapp-1.0.so.0 => /lib/x86_64-linux-gnu/libgstapp-1.0.so.0 (0x000071a8e94cb000)
        libgstbase-1.0.so.0 => /lib/x86_64-linux-gnu/libgstbase-1.0.so.0 (0x000071a8e9446000)
        libgstreamer-1.0.so.0 => /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0 (0x000071a8e92f5000)
        libgstpbutils-1.0.so.0 => /lib/x86_64-linux-gnu/libgstpbutils-1.0.so.0 (0x000071a8e92b1000)
        libgstaudio-1.0.so.0 => /lib/x86_64-linux-gnu/libgstaudio-1.0.so.0 (0x000071a8e922f000)
        libgsttag-1.0.so.0 => /lib/x86_64-linux-gnu/libgsttag-1.0.so.0 (0x000071a8e91ed000)
        libgstvideo-1.0.so.0 => /lib/x86_64-linux-gnu/libgstvideo-1.0.so.0 (0x000071a8e9128000)
        libgstgl-1.0.so.0 => /lib/x86_64-linux-gnu/libgstgl-1.0.so.0 (0x000071a8e90a0000)
        libgstfft-1.0.so.0 => /lib/x86_64-linux-gnu/libgstfft-1.0.so.0 (0x000071a8e9094000)
        libwebpdemux.so.2 => /lib/x86_64-linux-gnu/libwebpdemux.so.2 (0x000071a8e908e000)
        libwebp.so.7 => /lib/x86_64-linux-gnu/libwebp.so.7 (0x000071a8e901f000)
        libenchant-2.so.2 => /lib/x86_64-linux-gnu/libenchant-2.so.2 (0x000071a8e9011000)
        libsecret-1.so.0 => /lib/x86_64-linux-gnu/libsecret-1.so.0 (0x000071a8e8faf000)
        libtasn1.so.6 => /lib/x86_64-linux-gnu/libtasn1.so.6 (0x000071a8e8f97000)
        libhyphen.so.0 => /lib/x86_64-linux-gnu/libhyphen.so.0 (0x000071a8e8f90000)
        libwayland-server.so.0 => /lib/x86_64-linux-gnu/libwayland-server.so.0 (0x000071a8e8f7a000)
        libmanette-0.2.so.0 => /lib/x86_64-linux-gnu/libmanette-0.2.so.0 (0x000071a8e8f48000)
        libseccomp.so.2 => /lib/x86_64-linux-gnu/libseccomp.so.2 (0x000071a8e8f28000)
        libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x000071a8e8f17000)
        libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x000071a8e8f01000)
        /lib64/ld-linux-x86-64.so.2 (0x000071a8f23a2000)
        libatk-bridge-2.0.so.0 => /lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 (0x000071a8e8ec9000)
        libpsl.so.5 => /lib/x86_64-linux-gnu/libpsl.so.5 (0x000071a8e8eb3000)
        libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x000071a8e8ea5000)
        libgssapi_krb5.so.2 => /lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x000071a8e8e51000)
        libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x000071a8e8e0d000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x000071a8e8de1000)
        libatomic.so.1 => /lib/x86_64-linux-gnu/libatomic.so.1 (0x000071a8e8dd5000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x000071a8e8d5f000)
        libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x000071a8e8d52000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x000071a8e8d21000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x000071a8e8d18000)
        libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x000071a8e8d0d000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x000071a8e8d07000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x000071a8e8cff000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x000071a8e8cd4000)
        libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x000071a8e8c05000)
        liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x000071a8e8be3000)
        libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x000071a8e8bd8000)
        libicudata.so.70 => /lib/x86_64-linux-gnu/libicudata.so.70 (0x000071a8e6e00000)
        libwoff2common.so.1.0.2 => /lib/x86_64-linux-gnu/libwoff2common.so.1.0.2 (0x000071a8e8bd3000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x000071a8e8bad000)
        libunwind.so.8 => /lib/x86_64-linux-gnu/libunwind.so.8 (0x000071a8e8b90000)
        libdw.so.1 => /lib/x86_64-linux-gnu/libdw.so.1 (0x000071a8e8ae4000)
        liborc-0.4.so.0 => /lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x000071a8e8a5f000)
        libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x000071a8e6d79000)
        libEGL.so.1 => /lib/x86_64-linux-gnu/libEGL.so.1 (0x000071a8e8a4c000)
        libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x000071a8e8a45000)
        libgudev-1.0.so.0 => /lib/x86_64-linux-gnu/libgudev-1.0.so.0 (0x000071a8e8a37000)
        libevdev.so.2 => /lib/x86_64-linux-gnu/libevdev.so.2 (0x000071a8e6d5c000)
        libxcb-randr.so.0 => /lib/x86_64-linux-gnu/libxcb-randr.so.0 (0x000071a8e8a24000)
        libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x000071a8e6d0e000)
        libatspi.so.0 => /lib/x86_64-linux-gnu/libatspi.so.0 (0x000071a8e6cd4000)
        libunistring.so.2 => /lib/x86_64-linux-gnu/libunistring.so.2 (0x000071a8e6b2a000)
        libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x000071a8e6b09000)
        libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x000071a8e6ae6000)
        libkrb5.so.3 => /lib/x86_64-linux-gnu/libkrb5.so.3 (0x000071a8e6a1b000)
        libk5crypto.so.3 => /lib/x86_64-linux-gnu/libk5crypto.so.3 (0x000071a8e69ec000)
        libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x000071a8e69e6000)
        libkrb5support.so.0 => /lib/x86_64-linux-gnu/libkrb5support.so.0 (0x000071a8e69d8000)
        libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x000071a8e69a1000)
        libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x000071a8e690a000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x000071a8e68f2000)
        libelf.so.1 => /lib/x86_64-linux-gnu/libelf.so.1 (0x000071a8e68d4000)
        libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x000071a8e68c1000)
        libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x000071a8e6809000)
        libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x000071a8e67d5000)
        libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x000071a8e67ab000)
        libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x000071a8e67a2000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x000071a8e678e000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x000071a8e6781000)

aryzing avatar Jul 03 '24 20:07 aryzing

Thanks for sharing and we have got the culprit! Read the first line of the output

./libwebview.so: /lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by ./libwebview.so)

This dependency is missing on your system. https://stackoverflow.com/questions/20357033/usr-lib-x86-64-linux-gnu-libstdc-so-6-version-cxxabi-1-3-8-not-found should be worth checking out. Let me know if that fixed it. Cheers!

tr1ckydev avatar Jul 04 '24 04:07 tr1ckydev