在 Android 上构建时出现“后端错误:未定义的临时符号”

问题描述 投票:0回答:1

首先我从 opus-codec.org 下载了 opus 1.0.1 zip 包。然后我从 opus-1.0.1 文件夹中编写了 CMakeLists.txt 。 CMakeLists.txt 是从 github.com/berkus/opus 引用的。最后文件夹结构如下所示:

>myapp
 >app
 >opus
  >src
   >main
    >cpp
     >opus
      >opus-1.0.1
      -CMakeLists.txt

CMakeLists.txt 是

cmake_minimum_required(VERSION 3.4.1)
option(FIXED_POINT "Use fixed-point code (for device with less powerful FPU" NO)
option(USE_ALLOCA "Use alloca for stack arrays (on non-C99 compilers)" NO)
set(OPUS_VERSION 1.0.1)
set(OPUS_ROOT opus-${OPUS_VERSION})
set(CELT_SOURCES
    ${OPUS_ROOT}/celt/bands.c
    ${OPUS_ROOT}/celt/celt.c
    ${OPUS_ROOT}/celt/cwrs.c
    ${OPUS_ROOT}/celt/entcode.c
    ${OPUS_ROOT}/celt/entdec.c
    ${OPUS_ROOT}/celt/entenc.c
    ${OPUS_ROOT}/celt/kiss_fft.c
    ${OPUS_ROOT}/celt/laplace.c
    ${OPUS_ROOT}/celt/mathops.c
    ${OPUS_ROOT}/celt/mdct.c
    ${OPUS_ROOT}/celt/modes.c
    ${OPUS_ROOT}/celt/pitch.c
    ${OPUS_ROOT}/celt/celt_lpc.c
    ${OPUS_ROOT}/celt/quant_bands.c
    ${OPUS_ROOT}/celt/rate.c
    ${OPUS_ROOT}/celt/vq.c
)
set(SILK_SOURCES
    ${OPUS_ROOT}/silk/CNG.c
    ${OPUS_ROOT}/silk/code_signs.c
    ${OPUS_ROOT}/silk/init_decoder.c
    ${OPUS_ROOT}/silk/decode_core.c
    ${OPUS_ROOT}/silk/decode_frame.c
    ${OPUS_ROOT}/silk/decode_parameters.c
    ${OPUS_ROOT}/silk/decode_indices.c
    ${OPUS_ROOT}/silk/decode_pulses.c
    ${OPUS_ROOT}/silk/decoder_set_fs.c
    ${OPUS_ROOT}/silk/dec_API.c
    ${OPUS_ROOT}/silk/enc_API.c
    ${OPUS_ROOT}/silk/encode_indices.c
    ${OPUS_ROOT}/silk/encode_pulses.c
    ${OPUS_ROOT}/silk/gain_quant.c
    ${OPUS_ROOT}/silk/interpolate.c
    ${OPUS_ROOT}/silk/LP_variable_cutoff.c
    ${OPUS_ROOT}/silk/NLSF_decode.c
    ${OPUS_ROOT}/silk/NSQ.c
    ${OPUS_ROOT}/silk/NSQ_del_dec.c
    ${OPUS_ROOT}/silk/PLC.c
    ${OPUS_ROOT}/silk/shell_coder.c
    ${OPUS_ROOT}/silk/tables_gain.c
    ${OPUS_ROOT}/silk/tables_LTP.c
    ${OPUS_ROOT}/silk/tables_NLSF_CB_NB_MB.c
    ${OPUS_ROOT}/silk/tables_NLSF_CB_WB.c
    ${OPUS_ROOT}/silk/tables_other.c
    ${OPUS_ROOT}/silk/tables_pitch_lag.c
    ${OPUS_ROOT}/silk/tables_pulses_per_block.c
    ${OPUS_ROOT}/silk/VAD.c
    ${OPUS_ROOT}/silk/control_audio_bandwidth.c
    ${OPUS_ROOT}/silk/quant_LTP_gains.c
    ${OPUS_ROOT}/silk/VQ_WMat_EC.c
    ${OPUS_ROOT}/silk/HP_variable_cutoff.c
    ${OPUS_ROOT}/silk/NLSF_encode.c
    ${OPUS_ROOT}/silk/NLSF_VQ.c
    ${OPUS_ROOT}/silk/NLSF_unpack.c
    ${OPUS_ROOT}/silk/NLSF_del_dec_quant.c
    ${OPUS_ROOT}/silk/process_NLSFs.c
    ${OPUS_ROOT}/silk/stereo_LR_to_MS.c
    ${OPUS_ROOT}/silk/stereo_MS_to_LR.c
    ${OPUS_ROOT}/silk/check_control_input.c
    ${OPUS_ROOT}/silk/control_SNR.c
    ${OPUS_ROOT}/silk/init_encoder.c
    ${OPUS_ROOT}/silk/control_codec.c
    ${OPUS_ROOT}/silk/A2NLSF.c
    ${OPUS_ROOT}/silk/ana_filt_bank_1.c
    ${OPUS_ROOT}/silk/biquad_alt.c
    ${OPUS_ROOT}/silk/bwexpander_32.c
    ${OPUS_ROOT}/silk/bwexpander.c
    ${OPUS_ROOT}/silk/decode_pitch.c
    ${OPUS_ROOT}/silk/inner_prod_aligned.c
    ${OPUS_ROOT}/silk/lin2log.c
    ${OPUS_ROOT}/silk/log2lin.c
    ${OPUS_ROOT}/silk/LPC_analysis_filter.c
    ${OPUS_ROOT}/silk/LPC_inv_pred_gain.c
    ${OPUS_ROOT}/silk/table_LSF_cos.c
    ${OPUS_ROOT}/silk/NLSF2A.c
    ${OPUS_ROOT}/silk/NLSF_stabilize.c
    ${OPUS_ROOT}/silk/NLSF_VQ_weights_laroia.c
    ${OPUS_ROOT}/silk/pitch_est_tables.c
    ${OPUS_ROOT}/silk/resampler.c
    ${OPUS_ROOT}/silk/resampler_down2_3.c
    ${OPUS_ROOT}/silk/resampler_down2.c
    ${OPUS_ROOT}/silk/resampler_private_AR2.c
    ${OPUS_ROOT}/silk/resampler_private_down_FIR.c
    ${OPUS_ROOT}/silk/resampler_private_IIR_FIR.c
    ${OPUS_ROOT}/silk/resampler_private_up2_HQ.c
    ${OPUS_ROOT}/silk/resampler_rom.c
    ${OPUS_ROOT}/silk/sigm_Q15.c
    ${OPUS_ROOT}/silk/sort.c
    ${OPUS_ROOT}/silk/sum_sqr_shift.c
    ${OPUS_ROOT}/silk/stereo_decode_pred.c
    ${OPUS_ROOT}/silk/stereo_encode_pred.c
    ${OPUS_ROOT}/silk/stereo_find_predictor.c
    ${OPUS_ROOT}/silk/stereo_quant_pred.c
)
if (DEBUG)
    list(APPEND SILK_SOURCES ${OPUS_ROOT}/silk/debug.c)
endif (DEBUG)
if (FIXED_POINT)
    list(APPEND
         SILK_SOURCES
         ${OPUS_ROOT}/silk/fixed/LTP_analysis_filter_FIX.c
         ${OPUS_ROOT}/silk/fixed/LTP_scale_ctrl_FIX.c
         ${OPUS_ROOT}/silk/fixed/corrMatrix_FIX.c
         ${OPUS_ROOT}/silk/fixed/encode_frame_FIX.c
         ${OPUS_ROOT}/silk/fixed/find_LPC_FIX.c
         ${OPUS_ROOT}/silk/fixed/find_LTP_FIX.c
         ${OPUS_ROOT}/silk/fixed/find_pitch_lags_FIX.c
         ${OPUS_ROOT}/silk/fixed/find_pred_coefs_FIX.c
         ${OPUS_ROOT}/silk/fixed/noise_shape_analysis_FIX.c
         ${OPUS_ROOT}/silk/fixed/prefilter_FIX.c
         ${OPUS_ROOT}/silk/fixed/process_gains_FIX.c
         ${OPUS_ROOT}/silk/fixed/regularize_correlations_FIX.c
         ${OPUS_ROOT}/silk/fixed/residual_energy16_FIX.c
         ${OPUS_ROOT}/silk/fixed/residual_energy_FIX.c
         ${OPUS_ROOT}/silk/fixed/solve_LS_FIX.c
         ${OPUS_ROOT}/silk/fixed/warped_autocorrelation_FIX.c
         ${OPUS_ROOT}/silk/fixed/apply_sine_window_FIX.c
         ${OPUS_ROOT}/silk/fixed/autocorr_FIX.c
         ${OPUS_ROOT}/silk/fixed/burg_modified_FIX.c
         ${OPUS_ROOT}/silk/fixed/k2a_FIX.c
         ${OPUS_ROOT}/silk/fixed/k2a_Q16_FIX.c
         ${OPUS_ROOT}/silk/fixed/pitch_analysis_core_FIX.c
         ${OPUS_ROOT}/silk/fixed/vector_ops_FIX.c
         ${OPUS_ROOT}/silk/fixed/schur64_FIX.c
         ${OPUS_ROOT}/silk/fixed/schur_FIX.c)
else (FIXED_POINT)
    list(APPEND
         SILK_SOURCES
         ${OPUS_ROOT}/silk/float/apply_sine_window_FLP.c
         ${OPUS_ROOT}/silk/float/corrMatrix_FLP.c
         ${OPUS_ROOT}/silk/float/encode_frame_FLP.c
         ${OPUS_ROOT}/silk/float/find_LPC_FLP.c
         ${OPUS_ROOT}/silk/float/find_LTP_FLP.c
         ${OPUS_ROOT}/silk/float/find_pitch_lags_FLP.c
         ${OPUS_ROOT}/silk/float/find_pred_coefs_FLP.c
         ${OPUS_ROOT}/silk/float/LPC_analysis_filter_FLP.c
         ${OPUS_ROOT}/silk/float/LTP_analysis_filter_FLP.c
         ${OPUS_ROOT}/silk/float/LTP_scale_ctrl_FLP.c
         ${OPUS_ROOT}/silk/float/noise_shape_analysis_FLP.c
         ${OPUS_ROOT}/silk/float/prefilter_FLP.c
         ${OPUS_ROOT}/silk/float/process_gains_FLP.c
         ${OPUS_ROOT}/silk/float/regularize_correlations_FLP.c
         ${OPUS_ROOT}/silk/float/residual_energy_FLP.c
         ${OPUS_ROOT}/silk/float/solve_LS_FLP.c
         ${OPUS_ROOT}/silk/float/warped_autocorrelation_FLP.c
         ${OPUS_ROOT}/silk/float/wrappers_FLP.c
         ${OPUS_ROOT}/silk/float/autocorrelation_FLP.c
         ${OPUS_ROOT}/silk/float/burg_modified_FLP.c
         ${OPUS_ROOT}/silk/float/bwexpander_FLP.c
         ${OPUS_ROOT}/silk/float/energy_FLP.c
         ${OPUS_ROOT}/silk/float/inner_product_FLP.c
         ${OPUS_ROOT}/silk/float/k2a_FLP.c
         ${OPUS_ROOT}/silk/float/levinsondurbin_FLP.c
         ${OPUS_ROOT}/silk/float/LPC_inv_pred_gain_FLP.c
         ${OPUS_ROOT}/silk/float/pitch_analysis_core_FLP.c
         ${OPUS_ROOT}/silk/float/scale_copy_vector_FLP.c
         ${OPUS_ROOT}/silk/float/scale_vector_FLP.c
         ${OPUS_ROOT}/silk/float/schur_FLP.c
         ${OPUS_ROOT}/silk/float/sort_FLP.c
)
endif (FIXED_POINT)
set(OPUS_SOURCES
     ${OPUS_ROOT}/src/opus.c
     ${OPUS_ROOT}/src/opus_decoder.c
     ${OPUS_ROOT}/src/opus_encoder.c
     ${OPUS_ROOT}/src/opus_multistream.c
     ${OPUS_ROOT}/src/repacketizer.c
)
add_definitions(-DOPUS_VERSION="\\"${OPUS_VERSION}\\"")
# It is strongly recommended to uncomment one of these
# VAR_ARRAYS: Use C99 variable-length arrays for stack allocation
# USE_ALLOCA: Use alloca() for stack allocation
# If none is defined, then the fallback is a non-threadsafe global array
if (USE_ALLOCA)
    add_definitions(-DUSE_ALLOCA)
else (USE_ALLOCA)
    add_definitions(-DVAR_ARRAYS)
endif (USE_ALLOCA)
# These options affect performance
# HAVE_LRINTF: Use C99 intrinsics to speed up float-to-int conversion
add_definitions(-DHAVE_LRINTF)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wstrict-prototypes -Wextra -Wcast-align")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wnested-externs -Wshadow")
add_definitions(-DOPUS_BUILD)
if (FIXED_POINT)
    add_definitions(-DFIXED_POINT=1 -DDISABLE_FLOAT_API)
endif (FIXED_POINT)
include_directories(${OPUS_ROOT}/include
                    ${OPUS_ROOT}/silk
                    ${OPUS_ROOT}/silk/float
                    ${OPUS_ROOT}/silk/fixed
                    ${OPUS_ROOT}/celt
                    ${OPUS_ROOT}/src)
add_library(opus SHARED ${CELT_SOURCES} ${SILK_SOURCES} ${OPUS_SOURCES})

当我厌倦了在命令行中运行cmake.exe和ninja.exe时,它成功构建了libopus.so文件,这是命令

C:\Users\Administrator\Desktop\lang\opus\src\main\cpp\opus>cmake . -G"Android Gradle - Ninja" -D"ANDROID_ABI=arm64-v8a" -D"ANDROID_NDK=C:\Android\android-sdk\ndk-bundle" -D"CMAKE_BUILD_TYPE=Debug" -D"CMAKE_MAKE_PROGRAM=ninja" -D"CMAKE_TOOLCHAIN_FILE=C:\Android\android-sdk\ndk-bundle\build\cmake\android.toolchain.cmake" -D"ANDROID_NATIVE_API_LEVEL=21"
-- Check for working C compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- Check for working CXX compiler: C:/Android/android-sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus

C:\Users\Administrator\Desktop\lang\opus\src\main\cpp\opus>ninja
[128/128] Linking C shared library libopus.so

C:\Users\Administrator\Desktop\lang\opus\src\main\cpp\opus>

但是当我使用 Android Studio 用相同的代码构建库时,它失败了。

Gradle 文件是:

android {
    //other
    externalNativeBuild {
        cmake {
            path "src/main/cpp/opus/CMakeLists.txt"
        }
    }
    //other
}

错误信息是:

Error:FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':opus:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'C:\Android\android-sdk\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build C:\Users\Administrator\Desktop\lang\opus\.externalNativeBuild\cmake\debug\mips --target opus}
[1/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/enc_API.c.o
[2/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/NLSF_decode.c.o
[3/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/NSQ.c.o
[4/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/NSQ_del_dec.c.o
[5/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/PLC.c.o
[6/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/shell_coder.c.o
[7/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/tables_gain.c.o
[8/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/tables_LTP.c.o
[9/103] Building C object CMakeFiles/opus.dir/opus-1.0.1/silk/tables_NLSF_CB_NB_MB.c.o
FAILED: C:\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe  --target=mipsel-none-linux-android --gcc-toolchain=C:/Android/android-sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Android/android-sdk/ndk-bundle/platforms/android-9/arch-mips -DHAVE_LRINTF -DOPUS_BUILD -DOPUS_VERSION=\"\\\"1.0.1\\\"\" -DVAR_ARRAYS -Dopus_EXPORTS -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/include -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/silk -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/silk/float -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/silk/fixed -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/celt -IC:/Users/Administrator/Desktop/lang/opus/src/main/cpp/opus/opus-1.0.1/src -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mips32 -Wa,--noexecstack -Wformat -Werror=format-security  -Wall -W -Wstrict-prototypes -Wextra -Wcast-align -Wnested-externs -Wshadow -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/opus.dir/opus-1.0.1/silk/enc_API.c.o -MF CMakeFiles\opus.dir\opus-1.0.1\silk\enc_API.c.o.d -o CMakeFiles/opus.dir/opus-1.0.1/silk/enc_API.c.o   -c C:\Users\Administrator\Desktop\lang\opus\src\main\cpp\opus\opus-1.0.1\silk\enc_API.c
fatal error: error in backend: Undefined temporary symbol
  ninja: build stopped: subcommand failed.


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

或者,有人可以分享他们在 Android 上使用 CMake 构建 Opus 的经验吗?

android android-studio cmake android-ndk build.gradle
1个回答
2
投票

感谢@Tsyvarev 在他的评论中提供了有用的链接!

clang
似乎在为
{}
ABI 编译的
if
语句中打破了空括号
MIPS

检查代码或禁用

MIPS
如果未定位 ABI 编译。

© www.soinside.com 2019 - 2024. All rights reserved.