Flutter run -d linux (build process failed)

I’m trying to build demo (created by flutter create) flutter linux desktop application on NixOS with the following shell.nix:

with (import <nixpkgs> { });

mkShell {
  buildInputs = [
    at-spi2-core.dev
    clang
    cmake
    dart
    dbus.dev
    flutter
    gtk3
    libdatrie
    libepoxy.dev
    libselinux
    libsepol
    libthai
    libxkbcommon
    ninja
    pcre
    pkg-config
    util-linux.dev
    xorg.libXdmcp
    xorg.libXtst
  ];
}

I keep getting this cryptic error:

Launching lib/main.dart on Linux in debug mode...
Building Linux application...
/nix/store/js66s0xwjnzg0ggi2lq9bcvlk6x2za13-binutils-2.35.2/bin/ld: warning: libepoxy.so.0, needed by /home/domust/devel/flutter/myapp/linux/flutter/ephemeral/libflutter_linux_gtk.so, not found (try using -rpath or -rpath-link)
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
Exception: Build process failed

But I have libepoxy installed in shell.nix and I can verify it by running this command:

pkg-config --exists epoxy

because it returns 0.

I’ve also tried running flutter run -d linux -v to see more verbose logs and I see that flutter is unable to find specific symbols, for example:

[ +234 ms] [5/6] Linking CXX executable intermediates_do_not_run/myapp
[        ] FAILED: intermediates_do_not_run/myapp
[   +4 ms] : && /nix/store/ffic8fn216glbk94v899z5wj19p78716-clang-wrapper-7.1.0/bin/clang++ -g  CMakeFiles/myapp.dir/main.cc.o CMakeFiles/myapp.dir/my_application.cc.o CMakeFiles/myapp.dir/flutter/generated_plugin_registrant.cc.o -o intermediates_do_not_run/myapp -L/home/domust/devel/flutter/myapp/linux/flutter/ephemeral -Wl,-rpath,/home/domust/devel/flutter/myapp/linux/flutter/ephemeral:  -lflutter_linux_gtk  /nix/store/g2xxryy86xk29p8dgxggzz1q3qb1bhcm-gtk+3-3.24.30/lib/libgtk-3.so  /nix/store/g2xxryy86xk29p8dgxggzz1q3qb1bhcm-gtk+3-3.24.30/lib/libgdk-3.so  /nix/store/1l4r0r4ab3v3a3ppir4jwiah3icalk9d-zlib-1.2.11/lib/libz.so  /nix/store/b7hj8q3fg67ajzqnjjaklrk6z9rx7n66-pango-1.48.10/lib/libpangocairo-1.0.so  /nix/store/b7hj8q3fg67ajzqnjjaklrk6z9rx7n66-pango-1.48.10/lib/libpango-1.0.so  /nix/store/ad144da88q6pcqkl688dx3dkjzkl99yj-harfbuzz-3.0.0/lib/libharfbuzz.so  /nix/store/acicmcswclgs0gcaksmv6yrg697s68vn-atk-2.36.0/lib/libatk-1.0.so  /nix/store/kngsrd486pgbsac7wxz22b5qiv0c8761-cairo-1.16.0/lib/libcairo-gobject.so  /nix/store/kngsrd486pgbsac7wxz22b5qiv0c8761-cairo-1.16.0/lib/libcairo.so  /nix/store/7sbj7mc5wyrj9c9lv9vchyikm6792xmf-gdk-pixbuf-2.42.6/lib/libgdk_pixbuf-2.0.so  /nix/store/mbgcj6maiy41m0hacf1pw5nw56m3wn3q-glib-2.70.1/lib/libgio-2.0.so  /nix/store/mbgcj6maiy41m0hacf1pw5nw56m3wn3q-glib-2.70.1/lib/libgobject-2.0.so  /nix/store/mbgcj6maiy41m0hacf1pw5nw56m3wn3q-glib-2.70.1/lib/libglib-2.0.so && :
[        ] /nix/store/js66s0xwjnzg0ggi2lq9bcvlk6x2za13-binutils-2.35.2/bin/ld: warning: libepoxy.so.0, needed by /home/domust/devel/flutter/myapp/linux/flutter/ephemeral/libflutter_linux_gtk.so, not found (try using -rpath or -rpath-link)
[        ] /nix/store/js66s0xwjnzg0ggi2lq9bcvlk6x2za13-binutils-2.35.2/bin/ld: /nix/store/g2xxryy86xk29p8dgxggzz1q3qb1bhcm-gtk+3-3.24.30/lib/libgdk-3.so: undefined reference to `epoxy_eglDestroyContext'
[        ] /nix/store/js66s0xwjnzg0ggi2lq9bcvlk6x2za13-binutils-2.35.2/bin/ld: /nix/store/g2xxryy86xk29p8dgxggzz1q3qb1bhcm-gtk+3-3.24.30/lib/libgdk-3.so: undefined reference to `epoxy_glXCreateNewContext'

but I have these installed:

pkg-config --list-all | grep -i eg
xkbregistry               xkbregistry - XKB API to query available rules, models, layouts, variants and options
cairo-egl                 cairo-egl - EGL functions for cairo graphics library
libturbojpeg              libturbojpeg - A SIMD-accelerated JPEG codec that provides the TurboJPEG API
gl                        gl - Legacy OpenGL and GLX library and headers
egl                       egl - EGL library and headers
wayland-egl-backend       wayland-egl-backend - Backend wayland-egl interface
libjpeg                   libjpeg - A SIMD-accelerated JPEG codec that provides the libjpeg API
libpcre                   libpcre - PCRE - Perl compatible regular expressions C library with 8 bit character support
wayland-egl               wayland-egl - Frontend wayland-egl library
harfbuzz-gobject          harfbuzz-gobject - HarfBuzz text shaping library GObject integration

and

pkg-config --list-all | grep -i gl
gio-unix-2.0              GIO unix specific APIs - unix specific headers for glib I/O library
gio-2.0                   GIO - glib I/O library
gmodule-2.0               GModule - Dynamic module loader for GLib
glib-2.0                  GLib - C Utility Library
cairo-egl                 cairo-egl - EGL functions for cairo graphics library
gl                        gl - Legacy OpenGL and GLX library and headers
glproto                   GLProto - GL extension headers
gmodule-no-export-2.0     GModule - Dynamic module loader for GLib
glesv2                    gles2 - OpenGL ES v2/v3 library and headers
egl                       egl - EGL library and headers
wayland-egl-backend       wayland-egl-backend - Backend wayland-egl interface
cairo-glx                 cairo-glx - GLX functions for cairo graphics library
gmodule-export-2.0        GModule - Dynamic module loader for GLib
gobject-2.0               GObject - GLib Type, Object, Parameter and Signal Library
gthread-2.0               GThread - Thread support for GLib
glesv1_cm                 glesv1_cm - OpenGL ES-CM v1 library and headers
opengl                    opengl - OpenGL (without GLX) headers and interface
glx                       glx - GLX library and headers
epoxy                     epoxy - epoxy GL dispatch Library
cairo-gl                  cairo-gl - OpenGL surface backend for cairo graphics library
wayland-egl               wayland-egl - Frontend wayland-egl library
libglvnd                  libglvnd - Vendor-neutral OpenGL dispatch library vendor interface
xcb-glx                   XCB GLX - XCB GLX Extension

so I shouldn’t be missing any egl symbols :confused:

I have a feeling, that I’m probably missing one library, so if anyone has any ideas which library it might be, I’m all ears :grinning_face_with_smiling_eyes:

I was hinted that those missing symbols are definitely part of libepoxy and since they are generated from xml files, compilation might have missed that so I have decided to check:

pkg-config --libs epoxy # finding library location
-L/nix/store/6hrnnswjjc447ad7jijyxcmhfplnx0jz-libepoxy-1.5.4/lib -lepoxy
nm -gD /nix/store/6hrnnswjjc447ad7jijyxcmhfplnx0jz-libepoxy-1.5.4/lib/libepoxy.so | grep epoxy_eglDestroyContext
00000000001359a0 D epoxy_eglDestroyContext

The symbol is actually there… :confused: which means that I’m missing some linker flags and not libraries :thinking:

I have managed to get this working! The resulting shell.nix:

with (import <nixpkgs> { });

mkShell {
  buildInputs = [
    at-spi2-core.dev
    clang
    cmake
    dart
    dbus.dev
    flutter
    gtk3
    libdatrie
    libepoxy.dev
    libselinux
    libsepol
    libthai
    libxkbcommon
    ninja
    pcre
    pkg-config
    util-linux.dev
    xorg.libXdmcp
    xorg.libXtst
  ];
  shellHook = ''
    export LD_LIBRARY_PATH=${libepoxy}/lib
  '';
}

Linking of C/C++ programs under NixOS is described here: C - NixOS Wiki
NIX_FLAGS_COMPILE is populated by pkg-config --cflags <library-name>
NIX_LDFLAGS is populated by pkg-config --libs <library-name>
libepoxy was found in both of those variables, since pkg-config detects it as installed.

The problem was that flutter does not use NixOS way to look for libraries during linking (most likely a bug in the package), so LD_LIBRARY_PATH, which is unused on NixOS must be set.

4 Likes

Just wanted to leave a thank you. I struggled to get it running on my system as well :slight_smile:

:heart:

Thanks from me too :wink:

This is still working nicely with flutter-3.0.4.

Just an addition: when I mixed packages from unstable and stable (basically only taking unstable for dart and flutter, I got the following:

/nix/store/n63a18nr03vrw9qd76rz3hj2p5ssj96j-cmake-3.22.3/bin/cmake: error while loading shared libraries: __vdso_gettimeofday: invalid mode for dlopen(): Invalid argument

So that’s apparently not a good idea, probably caused by mismatches between libs and tools in the impure env (I’m using direnv).

Hosted by Flying Circus.