nba-emu / NanoBoyAdvance

A cycle-accurate Nintendo Game Boy Advance emulator.
GNU General Public License v3.0
974 stars 56 forks source link

unarr linking error in Flatpak build #261

Open robbie01 opened 2 years ago

robbie01 commented 2 years ago

I'm trying to find out if it's feasible to package NanoBoyAdvance as a Flatpak. (I do not intend to distribute it without the maintainer(s', 's) blessing.) It compiles fine, until the final link, when it spits out an error containing all of the unarr symbols that it can't find.

FAILED: bin/qt/NanoBoyAdvance 
: && /usr/bin/c++ -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer  -DGLEW_NO_GLU -O3 -DNDEBUG -L/app/lib -Wl,-z,relro,-z,now -Wl,--as-needed   -rdynamic bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/NanoBoyAdvance-Qt_autogen/mocs_compilation.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/widget/controller_manager.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/widget/input_window.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/widget/main_window.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/widget/screen.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/config.cpp.o bin/qt/CMakeFiles/NanoBoyAdvance-Qt.dir/src/main.cpp.o -o bin/qt/NanoBoyAdvance  src/platform/core/libplatform-core.a  /usr/lib/x86_64-linux-gnu/libQt6OpenGLWidgets.so.6.3.1  external/unarr/libunarr.a  src/nba/libnba.a  external/fmtlib/libfmt.a  -lSDL2  -lpthread  /usr/lib/x86_64-linux-gnu/libGL.so  /app/lib/libGLEW.so  /usr/lib/x86_64-linux-gnu/libQt6Widgets.so.6.3.1  /usr/lib/x86_64-linux-gnu/libQt6OpenGL.so.6.3.1  /usr/lib/x86_64-linux-gnu/libQt6Gui.so.6.3.1  /usr/lib/x86_64-linux-gnu/libGLX.so  /usr/lib/x86_64-linux-gnu/libOpenGL.so  /usr/lib/x86_64-linux-gnu/libQt6Core.so.6.3.1  -pthread && :
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: src/platform/core/libplatform-core.a(rom.cpp.o): in function `nba::ROMLoader::ReadFileFromArchive(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<unsigned char, std::allocator<unsigned char> >&)':
/run/build/nba/src/platform/core/src/loader/rom.cpp:139: undefined reference to `ar_open_file'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:145: undefined reference to `ar_open_zip_archive'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:158: undefined reference to `ar_parse_entry'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:159: undefined reference to `ar_entry_get_name'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:171: undefined reference to `ar_close_archive'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:172: undefined reference to `ar_close'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:163: undefined reference to `ar_entry_get_size'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:165: undefined reference to `ar_entry_uncompress'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:147: undefined reference to `ar_open_rar_archive'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:148: undefined reference to `ar_open_7z_archive'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:149: undefined reference to `ar_open_tar_archive'
/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/ld: /run/build/nba/src/platform/core/src/loader/rom.cpp:152: undefined reference to `ar_close'
collect2: error: ld returned 1 exit status

Note well that it has no complaints about finding external/unarr/libunarr.a, and an nm -g on that file shows that all of the missing symbols are there. I also built NBA on my host system in the exact same configuration with no issues, and I have tried adjusting various parameters (including using master and using Qt5) to no avail. The only thing I can think of is that it might be a link-order issue, though the host build succeeding leaves me skeptical.

Here is the Flatpak manifest:

# com.github.nba_emu.NanoBoyAdvance.yml

app-id: com.github.nba_emu.NanoBoyAdvance
runtime: org.kde.Platform
runtime-version: '6.3'
sdk: org.kde.Sdk
command: NanoBoyAdvance
finish-args:
  - "--share=ipc"
  - "--socket=fallback-x11"
  - "--socket=wayland"
  - "--socket=pulseaudio"
  - "--share=network"
  - "--device=all"
  - "--filesystem=home:ro"
modules:
  - shared-modules/glew/glew.json
  - name: nba
    buildsystem: cmake-ninja
    builddir: true
    build-options:
      cflags: -DGLEW_NO_GLU
      cxxflags: -DGLEW_NO_GLU
    config-opts:
      - -DCMAKE_BUILD_TYPE=Release
      - -DUSE_QT6=ON
      - -DPLATFORM_SDL2=OFF
    post-install:
      - install -Dt /app/bin bin/qt/NanoBoyAdvance
    sources:
      - type: git
        url: https://github.com/nba-emu/NanoBoyAdvance.git
        tag: v1.6
        commit: 3a43a7709fde9fa3d044b9d1ca91ee524d4c3973

To build it, you will need flathub/shared-modules in the same directory, the Flatpaks org.kde.Sdk//6.3 and org.kde.Platform//6.3, and flatpak-builder.

Run the following to reproduce:

flatpak-builder build-dir com.github.nba_emu.NanoBoyAdvance.yml

Thanks for any time spent looking into this.

Pixelnarium commented 1 year ago

This one works for me. It seems to be an issue with LTO on the unarr project. Sadly it is hardcoded and can't be disabled via flag. So I removed the flag with sed.

Still needs some improvements if you plan to release it on flathub (which would be great) ( see https://github.com/flathub/flathub/wiki/App-Requirements ):

runtime: org.kde.Platform
runtime-version: '6.4'
sdk: org.kde.Sdk
command: NanoBoyAdvance
finish-args:
  - --share=ipc
  - --socket=fallback-x11
  - --socket=wayland
  - --socket=pulseaudio
  - --share=network
  - --device=all
  - --persist=.

modules:
  - shared-modules/glew/glew.json
  - name: nba
    buildsystem: cmake-ninja
    builddir: true
    build-options:
      cflags: -DGLEW_NO_GLU
      cxxflags: -DGLEW_NO_GLU
    config-opts:
      - -DCMAKE_BUILD_TYPE=None
      - -DUSE_QT6=ON
    post-install:
      - install -Dt /app/bin bin/qt/NanoBoyAdvance
    sources:
      - type: git
        url: https://github.com/nba-emu/NanoBoyAdvance.git
        tag: v1.7
        commit: 1bcdaa39879c2d3c8db25d42a7439bc3a7555843
        x-checker-data:
          type: git
          tag-pattern: ^v([\d.]+)$
      - type: shell
        commands:
          - sed -i 's|-flto||g' external/unarr/CMakeLists.txt
JakobDev commented 1 year ago

Maybe opening a PR to add this things would be a good idea