Build error when CONFIG_USE_APK is enabled

I seem to get a lot of linking errors when building package/system/apk. Does anyone know what's wrong with my setup? GCC version is gcc (SUSE Linux) 13.3.0

make dirclean doesn't work.

[1/1] Linking target src/apk
FAILED: src/apk 
/home/qydw/openwrt/staging_dir/host/bin/gcc  -o src/apk src/apk.p/apk.c.o src/apk.p/app_adbdump.c.o src/apk.p/app_adbsign.c.o src/apk.p/app_add.c.o src/apk.p/app_audit.c.o src/apk.p/app_cache.c.o src/apk.p/app_convdb.c.o src/apk.p/app_convndx.c.o src/apk.p/app_del.c.o src/apk.p/app_dot.c.o src/apk.p/app_extract.c.o src/apk.p/app_fetch.c.o src/apk.p/app_fix.c.o src/apk.p/app_index.c.o src/apk.p/app_info.c.o src/apk.p/app_list.c.o src/apk.p/app_manifest.c.o src/apk.p/app_mkndx.c.o src/apk.p/app_mkpkg.c.o src/apk.p/app_policy.c.o src/apk.p/app_update.c.o src/apk.p/app_upgrade.c.o src/apk.p/app_search.c.o src/apk.p/app_stats.c.o src/apk.p/app_verify.c.o src/apk.p/app_version.c.o src/apk.p/applet.c.o -L/home/qydw/openwrt/staging_dir/host/lib -L/home/qydw/openwrt/staging_dir/hostpkg/lib -L/home/qydw/openwrt/staging_dir/target-mipsel_24kc_musl/host/lib -flto -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group src/libapk.a /home/qydw/openwrt/staging_dir/host/lib/libssl.a /home/qydw/openwrt/staging_dir/host/lib/libcrypto.a /home/qydw/openwrt/staging_dir/host/lib/libz.a /home/qydw/openwrt/staging_dir/host/lib/libzstd.a -Wl,--end-group -pthread
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `stats_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_stats.c:30:(.text+0x711): undefined reference to `apk_out_fmt'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `ver_indexes':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_version.c:33:(.text+0x76e): undefined reference to `apk_out_fmt'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `option_parse_global':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk.c:35:(.text+0x8ea): undefined reference to `apk_out_fmt'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk.c:186:(.text+0x932): undefined reference to `apk_io_url_set_timeout'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `option_parse_global':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk_defines.h:217:(.text+0x975): undefined reference to `_apk_array_grow'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `option_parse_global':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk.c:172:(.text+0xa61): undefined reference to `apk_io_url_no_check_certificate'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `option_parse_global':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk_defines.h:217:(.text+0xaa5): undefined reference to `_apk_array_grow'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `on_sigint':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk.c:405:(.text+0xb79): undefined reference to `apk_db_close'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbdump_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:15:(.text+0xba3): undefined reference to `adb_walk_gentext_ops'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:27:(.text+0xc16): undefined reference to `apk_ctx_get_trust'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbdump_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk_io.h:96:(.text+0xc2c): undefined reference to `__apk_istream_from_file'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbdump_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:27:(.text+0xc36): undefined reference to `adb_decompress'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:27:(.text+0xc46): undefined reference to `adb_walk_adb'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:31:(.text+0xc53): undefined reference to `apk_error_str'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:31:(.text+0xc6f): undefined reference to `apk_out_fmt'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbgen_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:51:(.text+0xcc7): undefined reference to `adb_walk_genadb_ops'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:56:(.text+0xcf6): undefined reference to `adb_w_init_dynamic'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:57:(.text+0xd19): undefined reference to `adb_w_init_dynamic'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:59:(.text+0xd38): undefined reference to `adb_reset'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:60:(.text+0xd44): undefined reference to `adb_reset'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbgen_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/apk_io.h:95:(.text+0xd54): undefined reference to `__apk_istream_from_file'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/tmp/ccACki5V.ltrans0.ltrans.o: in function `adbgen_main':
/home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:61:(.text+0xd63): undefined reference to `adb_walk_text'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:67:(.text+0xd75): undefined reference to `adb_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:68:(.text+0xd81): undefined reference to `adb_free'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:70:(.text+0xd88): undefined reference to `apk_error_str'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:70:(.text+0xda4): undefined reference to `apk_out_fmt'
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /home/qydw/openwrt/build_dir/hostpkg/apk-3.0.0_pre20241130/openwrt-build/../src/app_adbdump.c:63:(.text+0xdce): undefined reference to `adb_w_root'

What version is that
lsb_release -a

openSUSE Leap 15.6

Same error with GCC14

GNU ld (GNU Binutils; SUSE Linux Enterprise 15) 2.43.1.20240828-150100.7.49

Default is gcc7 , can you build host compilers with system default compiler?

gcc7 has other errors related to c++ features, so I chose the newest available gcc version.

Tools/packages necessary for building GCC
ISO C++14 compiler Necessary to bootstrap GCC. GCC 5.4 or newer has sufficient support for used C++14 features.

make dirclean doesn't work either

it is make distclean
Start with default compiler, if that does not work make minimal upgrades, error looks like lto-nonlto mixup during build.

1 Like

I nuked the config file and also enabled CONFIG_USE_LTO but still doesn't help

diff --git a/package/system/apk/Makefile b/package/system/apk/Makefile
index c045a990f0..038ce560f9 100644
--- a/package/system/apk/Makefile
+++ b/package/system/apk/Makefile
@@ -53,7 +53,7 @@ MESON_HOST_VARS+=VERSION=$(PKG_VERSION)
 MESON_VARS+=VERSION=$(PKG_VERSION)
 
 MESON_COMMON_ARGS = \
-       -Db_lto=true \
+       -Db_lto=false \
        -Dcompressed-help=false \
        -Ddocs=disabled \
        -Dhelp=enabled \

Setting b_lto to false solved it

Have not seen gcc7 any errors.

I doubt gcc-7 will see much (any?) testing with contemporary OpenWrt code.

LTO is used to reduce the binary size for apk considerably, so doing that is very much wanted for 8 MB flash devices, and semi-recent host compilers 'shouldn't' fall over this either…
/famous_last_words

It is about using host compiler used to build the build host kernel vs some latest version nobody else used, to built resonably recent openwrt cross-compiler.

GCC7 fix for patchelf was merged. I don't think it was ported to OpenWrt.

ccache requires GCC8.

what a weird error.

b_lto is mostly useful for target packages, not host. So a PR to move it is needed.

edit: can you try this patch?

--- a/src/meson.build
+++ b/src/meson.build
@@ -182,10 +182,10 @@ apk_exe = executable(
        apk_src,
        install: not subproject,
        dependencies: [
-               libapk_dep,
+               libfetch_dep,
+               libportability_dep,
                apk_deps,
-               libfetch_dep.partial_dependency(includes: true),
-               libportability_dep.partial_dependency(includes: true),
+               libapk_dep,
        ],
        c_args: apk_cargs,
 )

edit2: I tried reproducing under distrobox and leap 15.5. No dice.

Applying /home/qydw/openwrt/package/system/apk/patches/0001-patch.patch using plaintext: 
patching file src/meson.build
Hunk #1 FAILED at 182.
1 out of 1 hunk FAILED -- saving rejects to file src/meson.build.rej
Patch failed!  Please fix /home/qydw/openwrt/package/system/apk/patches/0001-patch.patch!

Clean build tree like a fresh clone in new place.