libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
433 stars 146 forks source link

Android build with SDL2MIXER_OPUS=ON can't find opusurl #458

Closed genpfault closed 2 years ago

genpfault commented 2 years ago

ld can't find opusurl with SDL2MIXER_OPUS=ON, causing the build to fail:

$ ./gradlew build

> Task :buildCMakeDebug FAILED
C/C++: ninja: Entering directory `/project-name/android/.cxx/Debug/6w2m3w14/arm64-v8a'
C/C++: clang: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: clang: error: linker command failed with exit code 1 (use -v to see invocation)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildCMakeDebug'.
> Build command failed.
  Error while executing process /android-sdk/cmake/3.18.1/bin/ninja with arguments {-C /project-name/android/.cxx/Debug/6w2m3w14/arm64-v8a SDL2 main modplug ogg opus opusfile opusfile_example seeking_example test_bitwise test_framing test_opus_decode test_opus_padding}
  ninja: Entering directory `/project-name/android/.cxx/Debug/6w2m3w14/arm64-v8a'
  [1/5] Linking C executable ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/opusfile_example
  FAILED: ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/opusfile_example 
  : && /android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android21 --gcc-toolchain=/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,--gc-sections external/sdl-mixer/external/opusfile/CMakeFiles/opusfile_example.dir/examples/opusfile_example.c.o -o ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/opusfile_example  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libopusfile.so  -lopusurl  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libogg.so  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libopus.so  -lm  -latomic -lm && :
  /android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lopusurl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  [2/5] Linking C executable ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/seeking_example
  FAILED: ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/seeking_example 
  : && /android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=aarch64-none-linux-android21 --gcc-toolchain=/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,--gc-sections external/sdl-mixer/external/opusfile/CMakeFiles/seeking_example.dir/examples/seeking_example.c.o -o ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/seeking_example  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libopusfile.so  -lopusurl  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libogg.so  ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libopus.so  -lm  -latomic -lm && :
  /android-sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lopusurl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  [3/5] Linking CXX shared library ../../../../build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libmodplug.so
  ninja: build stopped: subcommand failed.
...

CMakeLists.txt:

cmake_minimum_required( VERSION 3.18.0 )
cmake_policy( SET CMP0091 NEW )
project( appname )

set( SDL_LIBC ON CACHE BOOL "" FORCE )
set( SDL_TEST OFF CACHE BOOL "" FORCE )
# https://github.com/libsdl-org/SDL.git
# release-2.24.1
add_subdirectory( external/sdl )

set( BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_FLAC OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_OPUS ON CACHE BOOL "" FORCE )
set( SDL2MIXER_SAMPLES OFF CACHE BOOL "" FORCE )
set( SDL2MIXER_VENDORED ON CACHE BOOL "" FORCE )
# https://github.com/libsdl-org/SDL_mixer.git
# HEAD of 'main' branch as of today: db9da3d416077195a2f84403b2fb40955518b4ab
add_subdirectory( external/sdl-mixer )

set( SRCS "src/main.cpp" )

set( LIBS
    SDL2::SDL2main
    SDL2::SDL2-static
    SDL2_mixer::SDL2_mixer-static
    )

if( ${CMAKE_SYSTEM_NAME} MATCHES "Android")
    add_library( main SHARED ${SRCS} )
    target_link_libraries( main ${LIBS} )
else()
    add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} )
    target_link_libraries( ${CMAKE_PROJECT_NAME} ${LIBS} )
endif()

src/main.cpp:

#include <SDL.h>
#include <SDL_mixer.h>

int main( int argc, char** argv )
{
    SDL_Init( SDL_INIT_EVERYTHING );
    SDL_Quit();
    return 0;
}

The same CMakeLists.txt builds successfully with SDL2MIXER_OPUS=OFF, as well as on the host Debian 11 system with:

cmake -B build -G "Ninja Multi-Config" .
cmake --build build --config Release --parallel $(nproc)
sezero commented 2 years ago

How? We don't use or link to opusurl - at least we shouldn't. @madebr?

sezero commented 2 years ago

Looks like it's building opusfile examples and opus tests. Should we set OP_DISABLE_EXAMPLES to TRUE for opusfile and BUILD_TESTING to FALSE for opus?? (Maybe some others, as well??..)

slouken commented 2 years ago

Looks like it's building opusfile examples and opus tests. Should we set OP_DISABLE_EXAMPLES to TRUE for opusfile and BUILD_TESTING to FALSE for opus?? (Maybe some others, as well??..)

Yes, this sounds like a good idea.

genpfault commented 2 years ago

Well, with those two PRs applied (main pulled up to 58497bdb6ae7dee132bc538072ea3ce12a6e7c50) the ld: cannot find -lopusurl issue is fixed but now it can't find libopus.so:

$ ./gradlew build
...
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildCMakeDebug'.
> Expected output file at /project-name/android/build/intermediates/cxx/Debug/6w2m3w14/obj/arm64-v8a/libopus.so for target opus but there was none
...
genpfault commented 2 years ago

Setting SDL2MIXER_DEPS_SHARED=OFF lets the build complete.