I’m trying to get a dynamically linked binary running on a ubuntu without using system dependencies.
It’s a proprietary binary and I don’t have access to the src, so I can’t compile it differently or anything like that.
I’ve gotten it to start, i.e. it finds all dyn libs, but than it crashes.
This is how I’m “packaging” it:
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs { };
fantom_src = ./fantom;
fantom_patched = pkgs.stdenv.mkDerivation
{
name = "fantom_patched";
src = fantom_src;
dontConfigure = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mkdir -p $out/include
mkdir -p $out/lib
mkdir -p $out/share
cp -r bin $out/
cp -r include $out/
cp -r lib $out/
cp -r share $out/
runHook postInstall
'';
preFixup =
let
libPath = pkgs.lib.makeLibraryPath (with pkgs; [
libGL
libsForQt5.full
python312
stdenv.cc.cc.lib
]);
in
''
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
$out/bin/fantom
patchelf \
--set-rpath "${libPath}:$out/lib:$out/lib/fantom-plugins/utils" \
$out/bin/fantom \
$out/lib/libfantom-lib.so \
$out/lib/fantom-plugins/utils/libColorMap.so \
$out/lib/fantom-plugins/utils/libdatastructures.so \
$out/lib/fantom-plugins/utils/libGraphics.so \
$out/lib/fantom-plugins/utils/libmath.so \
$out/lib/fantom-plugins/utils/libMuParser.so
'';
};
in
# see https://nixos.wiki/wiki/Packaging/Binaries
pkgs.mkShell {
packages = with pkgs;
[
niv
cmake
virtualglLib
cmakeCurses
fantom_patched
];
QT_QPA_PLATFORM_PLUGIN_PATH = with pkgs.libsForQt5;
"${qt5.qtbase.bin}/lib/qt-${qt5.qtbase.version}/plugins";
QT_XCB_GL_INTEGRATION = "none";
# QT_SELECTION = "${ pkgs.libsForQt5.qt5.qtbase.dev }/bin";
# QT_QPA_DEFAULT_PLATFORM = "xcb";
# QT_WAYLAND_CLIENT_BUFFER_INTEGRATION = "xcomposite-egl";
# LD_LIBRARY_PATH = "${pkgs.mesa.drivers}/lib";
}
with sources.json
{
"nixpkgs": {
"branch": "nixos-unstable",
"description": "Nix Packages collection",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "18536bf04cd71abd345f9579158841376fdd0c5a",
"sha256": "0cy2cfyq9izqnybpqbn3q4pwcfxg0dkkcd3wwvbh4h98m51qxzs4",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/18536bf04cd71abd345f9579158841376fdd0c5a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
i.e. nixpkgs pretty much from today.
ldd
finds all libs in the nix store, which was my goal.
$ ldd $(which fantom)
linux-vdso.so.1 (0x00007ffcbb2e7000)
libGraphics.so => /nix/store/gr9nasxn95bsxi9ygd3i6msc2lj7302v-fantom_patched/lib/fantom-plugins/utils/libGraphics.so (0x00007f3ace187000)
libOpenGL.so.0 => /nix/store/vpys8vaqmjlzcn12wfccym7kgl7b3fr1-libglvnd-1.7.0/lib/libOpenGL.so.0 (0x00007f3ace15a000)
libQt5OpenGL.so.5 => /nix/store/ng9f6dc3xrv8xkysj5cs6wm2k5yz03k0-qt-full-5.15.15/lib/libQt5OpenGL.so.5 (0x00007f3acdba2000)
libQt5Svg.so.5 => /nix/store/ng9f6dc3xrv8xkysj5cs6wm2k5yz03k0-qt-full-5.15.15/lib/libQt5Svg.so.5 (0x00007f3acdb44000)
libQt5Widgets.so.5 => /nix/store/ng9f6dc3xrv8xkysj5cs6wm2k5yz03k0-qt-full-5.15.15/lib/libQt5Widgets.so.5 (0x00007f3acd400000)
libQt5Gui.so.5 => /nix/store/ng9f6dc3xrv8xkysj5cs6wm2k5yz03k0-qt-full-5.15.15/lib/libQt5Gui.so.5 (0x00007f3accc00000)
libQt5Core.so.5 => /nix/store/ng9f6dc3xrv8xkysj5cs6wm2k5yz03k0-qt-full-5.15.15/lib/libQt5Core.so.5 (0x00007f3acc600000)
libfantom-lib.so => /nix/store/gr9nasxn95bsxi9ygd3i6msc2lj7302v-fantom_patched/lib/libfantom-lib.so (0x00007f3acc200000)
libpython3.12.so.1.0 => /nix/store/wfbjq35kxs6x83c3ncpfxdyl5gbhdx4h-python3-3.12.6/lib/libpython3.12.so.1.0 (0x00007f3acba00000)
libstdc++.so.6 => /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libstdc++.so.6 (0x00007f3acb600000)
libm.so.6 => /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libm.so.6 (0x00007f3acd319000)
libgcc_s.so.1 => /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libgcc_s.so.1 (0x00007f3acdb1f000)
libc.so.6 => /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libc.so.6 (0x00007f3acb407000)
libgomp.so.1 => /nix/store/y3kdn61k93rq2jx1lj2x72lnsk0l92qh-gcc-13.3.0-lib/lib/libgomp.so.1 (0x00007f3acdad2000)
libGLdispatch.so.0 => /nix/store/vpys8vaqmjlzcn12wfccym7kgl7b3fr1-libglvnd-1.7.0/lib/libGLdispatch.so.0 (0x00007f3acc547000)
libGL.so.1 => /nix/store/vpys8vaqmjlzcn12wfccym7kgl7b3fr1-libglvnd-1.7.0/lib/libGL.so.1 (0x00007f3acc4b9000)
libpthread.so.0 => /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libpthread.so.0 (0x00007f3acd314000)
libz.so.1 => /nix/store/haci0d018njygwdga95bsbx8ww2iswy7-zlib-1.3.1/lib/libz.so.1 (0x00007f3acd2f6000)
libpng16.so.16 => /nix/store/4z21lw9vsbwir6zcpfrd9xvcrwdfzqk6-libpng-apng-1.6.43/lib/libpng16.so.16 (0x00007f3acd2bb000)
libharfbuzz.so.0 => /nix/store/ckmsqq30bk7i7ykkl7dydcjj609h67pr-harfbuzz-9.0.0/lib/libharfbuzz.so.0 (0x00007f3acb8c4000)
libicui18n.so.74 => /nix/store/0m07jsiadwxy9la4s33dyr491k83dsh8-icu4c-74.2/lib/libicui18n.so.74 (0x00007f3acb000000)
libicuuc.so.74 => /nix/store/0m07jsiadwxy9la4s33dyr491k83dsh8-icu4c-74.2/lib/libicuuc.so.74 (0x00007f3acac00000)
libicudata.so.74 => /nix/store/0m07jsiadwxy9la4s33dyr491k83dsh8-icu4c-74.2/lib/libicudata.so.74 (0x00007f3ac8e00000)
libpcre2-16.so.0 => /nix/store/zxk207030dbrz6ikiq61sz2c08gpljxq-pcre2-10.44/lib/libpcre2-16.so.0 (0x00007f3acc16c000)
libzstd.so.1 => /nix/store/iq0g82wwi93fj8gd768pyha40vyg5gx8-zstd-1.5.6/lib/libzstd.so.1 (0x00007f3acaf2c000)
libgthread-2.0.so.0 => /nix/store/fxnchbq09sq279ssqdsgzigsyvp6hz06-glib-2.80.4/lib/libgthread-2.0.so.0 (0x00007f3acd2b6000)
libglib-2.0.so.0 => /nix/store/fxnchbq09sq279ssqdsgzigsyvp6hz06-glib-2.80.4/lib/libglib-2.0.so.0 (0x00007f3ac8cb0000)
/nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/ld-linux-x86-64.so.2 => /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib64/ld-linux-x86-64.so.2 (0x00007f3ace1b7000)
libdl.so.2 => /nix/store/sl141d1g77wvhr050ah87lcyz2czdxa3-glibc-2.40-36/lib/libdl.so.2 (0x00007f3acd2af000)
libGLX.so.0 => /nix/store/vpys8vaqmjlzcn12wfccym7kgl7b3fr1-libglvnd-1.7.0/lib/libGLX.so.0 (0x00007f3acb890000)
libX11.so.6 => /nix/store/nicg80r560lxr1vzlrjcj401v98fwb7y-libX11-1.8.10/lib/libX11.so.6 (0x00007f3ac8b64000)
libXext.so.6 => /nix/store/9sixykfzghlh1apfc9iwmdmmdk6z92xd-libXext-1.3.6/lib/libXext.so.6 (0x00007f3acd298000)
libfreetype.so.6 => /nix/store/lfpg1k4nxpms35czil5j008s4na6qw0c-freetype-2.13.3/lib/libfreetype.so.6 (0x00007f3acae5a000)
libgraphite2.so.3 => /nix/store/qc4rglpf5rwxh7zfzxb4yrl3yfiraqkj-graphite2-1.3.14/lib/libgraphite2.so.3 (0x00007f3acb866000)
libpcre2-8.so.0 => /nix/store/zxk207030dbrz6ikiq61sz2c08gpljxq-pcre2-10.44/lib/libpcre2-8.so.0 (0x00007f3acb367000)
libxcb.so.1 => /nix/store/cv6gfvhz8s4fbxri7h297z61dgp4k8nv-libxcb-1.17.0/lib/libxcb.so.1 (0x00007f3acae2e000)
libbz2.so.1 => /nix/store/5x0kqz9xa737546fc009xkandg19l3ra-bzip2-1.0.8/lib/libbz2.so.1 (0x00007f3accbeb000)
libbrotlidec.so.1 => /nix/store/r9bd7jib7yl6p62h2gz40q7ki4si3r93-brotli-1.1.0-lib/lib/libbrotlidec.so.1 (0x00007f3accbdc000)
libXau.so.6 => /nix/store/1hjm6ivs0jmhs93g4x92pw1b1ixpkvg9-libXau-1.0.11/lib/libXau.so.6 (0x00007f3acc4b4000)
libXdmcp.so.6 => /nix/store/xzbl9y7bsf658g6cvdp4nbyl6ma08mm4-libXdmcp-1.1.5/lib/libXdmcp.so.6 (0x00007f3acc4ac000)
libbrotlicommon.so.1 => /nix/store/r9bd7jib7yl6p62h2gz40q7ki4si3r93-brotli-1.1.0-lib/lib/libbrotlicommon.so.1 (0x00007f3acabdd000)
Now the problem is that the app crashes on startup:
Gtk-Message: 15:17:34.606: Failed to load module "appmenu-gtk-module"
Gtk-Message: 15:17:34.672: Failed to load module "canberra-gtk-module"
Gtk-Message: 15:17:34.672: Failed to load module "canberra-gtk-module"
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QXcbIntegration: Cannot create platform offscreen surface, neither GLX nor EGL are enabled
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
QOpenGLWidget: Failed to create context
terminate called after throwing an instance of 'fantom::runtime_error'
what(): Unable to compile shader:
Aborted (core dumped)
The issue is that I have no idea about the inner workings of qt, opengl, glx/egl and x11 and how nix handles these.
I tried various combinations of QT env vars, but to no success so far.
{
QT_QPA_PLATFORM_PLUGIN_PATH = with pkgs.libsForQt5;
"${qt5.qtbase.bin}/lib/qt-${qt5.qtbase.version}/plugins";
QT_XCB_GL_INTEGRATION = "none";
}
and
{
QT_QPA_PLATFORM_PLUGIN_PATH = with pkgs.libsForQt5;
"${qt5.qtbase.bin}/lib/qt-${qt5.qtbase.version}/plugins/platforms";
}
lead to the same error, while just
{
QT_QPA_PLATFORM_PLUGIN_PATH = with pkgs.libsForQt5;
"${qt5.qtbase.bin}/lib/qt-${qt5.qtbase.version}/plugins";
}
will crash startup even earlier it seems:
Gtk-Message: 15:21:59.081: Failed to load module "appmenu-gtk-module"
Gtk-Message: 15:21:59.159: Failed to load module "canberra-gtk-module"
Gtk-Message: 15:21:59.160: Failed to load module "canberra-gtk-module"
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize-1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::CoreProfile)
qt.glx: qglx_findConfig: Failed to finding matching FBConfig for QSurfaceFormat(version 3.3, options QFlags<QSurfaceFormat::FormatOption>(), depthBufferSize -1, redBufferSize 1, greenBufferSize 1, blueBufferSize 1, alphaBufferSize-1, stencilBufferSize -1, samples -1, swapBehavior QSurfaceFormat::SingleBuffer, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::CoreProfile)
Could not initialize GLX
Aborted (core dumped)
I also tried starting the app with nixGL, which did not change things for me.