MusicPlayerDaemon / MPD

Music Player Daemon
https://www.musicpd.org/
GNU General Public License v2.0
2.18k stars 352 forks source link

Android compilation error #1375

Closed amrx06 closed 7 months ago

amrx06 commented 2 years ago

Bug report

Describe the bug

Compilation of MPD for Android fails on a fresh new Ubuntu 20 with all required packages, Android NDKr23b and Android SDK 29 and unmodified MPD source code fails.

The command to compile is the one from MPD manual:

mkdir -p output/android cd output/android ../../android/build.py $SDK_PATH $NDK_PATH $ABI \ --buildtype=debugoptimized -Db_ndebug=true \ -Dwrap_mode=forcefallback \ -Dandroid_debug_keystore=$HOME/.android/debug.keystore ninja android/apk/mpd-debug.apk

Expected Behavior

Compilation of MPD is successful.

Actual Behavior

Compilation fails.

Version

source code version 0.24

Log

/home/elfire/Downloads/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -Isrc/fs/libfs.a.p -Isrc/fs -I../../src/fs -Isrc -I../../src -I. -I../.. -I../../subprojects/fmt-7.1.3/include -I/usr/include -I/home/elfire/Downloads/MPD/output/android/android/include -Xclang -fcolor-diagnostics -DNDEBUG -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++17 O2 -g -ffast-math -ftree-vectorize -Wcast-qual -Wdouble-promotion -Wmissing-declarations -Wshadow -Wunused -Wvla -Wwrite-strings -Wunreachable-code-aggressive -Wused-but-marked-unused -fno-threadsafe-statics -fmerge-all-constants -Wextra-semi -Wmismatched-tags -Woverloaded-virtual -Wsign-promo -Wno-non-virtual-dtor -Wcomma -Wheader-hygiene -Winconsistent-missing-destructor-override -Wsuggest-override -fvisibility=hidden -ffunction-sections -fdata-sections -D_GNU_SOURCE -DANDROID -isystem /home/elfire/Downloads/MPD/output/android/lib/arm-linux-androideabi/root/include -Os -g -fpic -mfpu=neon -mfloat-abi=softfp -target armv7-linux-androideabi21 -fvisibility=hidden -fdata-sections -ffunction-sections -fPIC -MD -MQ src/fs/libfs.a.p/CheckFile.cxx.o -MF src/fs/libfs.a.p/CheckFile.cxx.o.d -o src/fs/libfs.a.p/CheckFile.cxx.o -c ../../src/fs/CheckFile.cxx

results in:

c ../../src/fs/CheckFile.cxx In file included from ../../src/fs/CheckFile.cxx:22: In file included from ../../src/lib/fmt/PathFormatter.hxx:26: In file included from ../../subprojects/fmt-7.1.3/include/fmt/format.h:38: /home/elfire/Downloads/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace; did you mean '__signbit'? using ::signbit;

Hint: I guess it's related to c++17 standard. I added -std=c++17 in android/build.py: libstdcxx_libs = '-std=c++17 -static-libstdc++' with or without this modification the result is exactly the same.

If it's a c++17 problem, there are 2 options: 1/ having a compliant cross compiling toolchain. MPD uses the one from Android SDK without other option, at least when following instructions from MPD manual.

2/ adding an option in android/build.py or somewhere else to ask the compiler to be c++17 compliant. This is the way I am investigating.

MaxKellermann commented 2 years ago

Your compiler command you already use -std=c++17, so what's the point of adding it again?

The problem here is: -I/usr/include which causes host headers to be included. Find out why that option was used.

amrx06 commented 2 years ago

Great, removing [-I/usr/include] compiles successfully, with and without -std=c++17. My question was: did I modified the correct line of android/build.py to add it? Nethertheless thanks to your answer it seems this modification is not required.

Now I need to investigate why there is this argument in build.ninja! It seems it is generated by android/build.py

amrx06 commented 2 years ago

I can't find the origin if this -I/usr/include. If I remove them all from ninja.build (with a dirty sed…) compilation continues but then linking fails for barely the same reason: /home/elfire/Downloads/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -o (...) -lz /usr/lib/x86_64-linux-gnu/libz.so (...) -lm /home/elfire/Downloads/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/arm-linux-androideabi/21/libz.so (...) ld: error: /usr/lib/x86_64-linux-gnu/libz.so is incompatible with armelf_linux_eabi

removing -lz /usr/lib/x86_64-linux-gnu/libz.so removes the error.

The compilation chain is polluted by /usr references, I can't figure why. Installation of Ubuntu is fresh new just to compile this project, there is maybe a step to configure it but which one?

MaxKellermann commented 2 years ago

Check the output/meson-* directories for clues.

amrx06 commented 2 years ago

any clue with this similar problem and cmake? https://github.com/android/ndk/issues/467 note: my make version is 3.18.4

sambazley commented 2 years ago

I'm getting the same problem on Arch. Looks like the problem is caused by Curl. From meson-logs/meson-log.txt:

Called `/home/sam/MPD/output/android/lib/aarch64-linux-android/root/bin/pkg-config --libs libcurl` -> 0
-L/home/sam/MPD/output/android/lib/aarch64-linux-android/root/lib -lcurl -ldl -pthread /home/sam/MPD/output/android/lib/aarch64-linux-android/root/lib/libssl.a /home/sam/MPD/output/android/lib/aarch64-linux-android/root/lib/libcrypto.a /usr/lib/libz.so
eli-schwartz commented 2 years ago

For reasons I don't understand, curl generally hardcodes a bunch of -l flags instead of using pkg-config dependencies. Meson is only supposed to look for those in the compiler directories reported by /home/elfire/Downloads/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --print-search-dirs, or (preferably) in the directory which pkg-config --libs.

In this case, curl is actually reporting something very strange and different: absolute paths to individual library files, which are the wrong library files in at least the case of libz.so

sambazley commented 2 years ago

Looks like it's caused by Curl's CMake scripts. As a work around, this patch reverts back to compile Curl with autotools.

From ade14e3a704d0e8d8491bee3ef419569bb534897 Mon Sep 17 00:00:00 2001
From: Sam Bazley <sambazley@fastmail.com>
Date: Sun, 26 Dec 2021 18:28:25 +0000
Subject: [PATCH] Revert "python/build/libs.py: build CURL with cmake"

This reverts commit 6acf81d5ae9bebaa3fec9a5d9aadf6aaddc4965e.
---
 python/build/libs.py                          | 51 +++++++++----------
 .../no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch  | 11 ----
 src/lib/curl/patches/only_lib.patch           | 15 ++++++
 src/lib/curl/patches/series                   |  2 +-
 4 files changed, 40 insertions(+), 39 deletions(-)
 delete mode 100644 src/lib/curl/patches/no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch
 create mode 100644 src/lib/curl/patches/only_lib.patch

diff --git a/python/build/libs.py b/python/build/libs.py
index dd69d9780eb9..e824621604c4 100644
--- a/python/build/libs.py
+++ b/python/build/libs.py
@@ -385,38 +385,35 @@ openssl = OpenSSLProject(
     'include/openssl/ossl_typ.h',
 )

-curl = CmakeProject(
+curl = AutotoolsProject(
     'https://curl.se/download/curl-7.79.1.tar.xz',
     '0606f74b1182ab732a17c11613cbbaf7084f2e6cca432642d0e3ad7c224c3689',
     'lib/libcurl.a',
     [
-        '-DBUILD_CURL_EXE=OFF',
-        '-DBUILD_SHARED_LIBS=OFF',
-        '-DCURL_DISABLE_VERBOSE_STRINGS=ON',
-        '-DCURL_DISABLE_LDAP=ON',
-        '-DCURL_DISABLE_TELNET=ON',
-        '-DCURL_DISABLE_DICT=ON',
-        '-DCURL_DISABLE_FILE=ON',
-        '-DCURL_DISABLE_FTP=ON',
-        '-DCURL_DISABLE_TFTP=ON',
-        '-DCURL_DISABLE_LDAPS=ON',
-        '-DCURL_DISABLE_RTSP=ON',
-        '-DCURL_DISABLE_PROXY=ON',
-        '-DCURL_DISABLE_POP3=ON',
-        '-DCURL_DISABLE_IMAP=ON',
-        '-DCURL_DISABLE_SMTP=ON',
-        '-DCURL_DISABLE_GOPHER=ON',
-        '-DCURL_DISABLE_COOKIES=ON',
-        '-DCURL_DISABLE_CRYPTO_AUTH=ON',
-        '-DCURL_DISABLE_ALTSVC=ON',
-        '-DCMAKE_USE_LIBSSH2=OFF',
-        '-DCURL_WINDOWS_SSPI=OFF',
-        '-DCURL_DISABLE_NTLM=ON',
-        '-DBUILD_TESTING=OFF',
-    ],
-    windows_configure_args=[
-        '-DCMAKE_USE_SCHANNEL=ON',
+        '--disable-shared', '--enable-static',
+        '--disable-debug',
+        '--enable-http',
+        '--enable-ipv6',
+        '--disable-ftp', '--disable-file',
+        '--disable-ldap', '--disable-ldaps',
+        '--disable-rtsp', '--disable-proxy', '--disable-dict', '--disable-telnet',
+        '--disable-tftp', '--disable-pop3', '--disable-imap', '--disable-smtp',
+        '--disable-smb',
+        '--disable-gopher',
+        '--disable-manual',
+        '--disable-threaded-resolver', '--disable-verbose', '--disable-sspi',
+        '--disable-crypto-auth', '--disable-ntlm-wb', '--disable-tls-srp', '--disable-cookies',
+        '--disable-doh',
+        '--disable-mime',
+        '--disable-netrc',
+        '--disable-progress-meter',
+        '--disable-alt-svc',
+        '--without-gnutls', '--without-nss', '--without-libssh2',
+
+        # native Windows SSL/TLS support, option ignored on non-Windows builds
+        '--with-schannel',
     ],
+
     patches='src/lib/curl/patches',
 )

diff --git a/src/lib/curl/patches/no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch b/src/lib/curl/patches/no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch
deleted file mode 100644
index d7d0ed6789d4..000000000000
--- a/src/lib/curl/patches/no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- curl-7.75.0.orig/CMakeLists.txt    2021-02-02 09:26:24.000000000 +0100
-+++ curl-7.75.0/CMakeLists.txt 2021-03-25 20:17:25.445684029 +0100
-@@ -1453,7 +1453,7 @@
- set(LDFLAGS                 "${CMAKE_SHARED_LINKER_FLAGS}")
- set(LIBCURL_LIBS            "")
- set(libdir                  "${CMAKE_INSTALL_PREFIX}/lib")
--foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
-+foreach(_lib ${CURL_LIBS})
-   if(TARGET "${_lib}")
-     set(_libname "${_lib}")
-     get_target_property(_libtype "${_libname}" TYPE)
diff --git a/src/lib/curl/patches/only_lib.patch b/src/lib/curl/patches/only_lib.patch
new file mode 100644
index 000000000000..2bc374983045
--- /dev/null
+++ b/src/lib/curl/patches/only_lib.patch
@@ -0,0 +1,15 @@
+Index: curl-7.58.0/Makefile.in
+===================================================================
+--- curl-7.58.0.orig/Makefile.in
++++ curl-7.58.0/Makefile.in
+@@ -641,8 +641,8 @@ CLEANFILES = $(VC6_LIBDSP) $(VC6_SRCDSP)
+  $(VC14_LIBVCXPROJ) $(VC14_SRCVCXPROJ) $(VC15_LIBVCXPROJ) $(VC15_SRCVCXPROJ)
+ 
+ bin_SCRIPTS = curl-config
+-SUBDIRS = lib src
+-DIST_SUBDIRS = $(SUBDIRS) tests packages scripts include docs
++SUBDIRS = lib
++DIST_SUBDIRS = $(SUBDIRS) include
+ pkgconfigdir = $(libdir)/pkgconfig
+ pkgconfig_DATA = libcurl.pc
+ LIB_VAUTH_CFILES = vauth/vauth.c vauth/cleartext.c vauth/cram.c         \
diff --git a/src/lib/curl/patches/series b/src/lib/curl/patches/series
index 979436b3c3a5..f9bd7bfe300d 100644
--- a/src/lib/curl/patches/series
+++ b/src/lib/curl/patches/series
@@ -1,2 +1,2 @@
-no_CMAKE_C_IMPLICIT_LINK_LIBRARIES.patch
+only_lib.patch
 no_netrc.patch
-- 
2.34.1
amrx06 commented 2 years ago

sounds an interesting solution thank you. It should be pulled to master branch.

I tried without success but baybe because I don't master git and ninja. By the way I compiled successfully with editing the ninja.build with sed and it runs smoothly on an android tv box.

amrx06 commented 8 months ago

you can close this thread. I was able to compile 23.14 without error