这是我完整的 Android.mk 文件,当我尝试构建它时,我遇到了链接器问题(请参阅下文)
LOCAL_PATH := $(call my-dir)
#
# Opus - low-latency audio codec
#
include $(CLEAR_VARS)
LOCAL_DIR := opus-1.0.3
LOCAL_MODULE := opus
LOCAL_CELT_SOURCES := \
$(LOCAL_DIR)/celt/bands.c \
...
LOCAL_SILK_SOURCES := \
$(LOCAL_DIR)/silk/CNG.c \
...
LOCAL_SILK_SOURCES_FIXED := \
$(LOCAL_DIR)/silk/fixed/LTP_analysis_filter_FIX.c \
...
LOCAL_SILK_SOURCES_FLOAT := \
$(LOCAL_DIR)/silk/float/apply_sine_window_FLP.c \
...
LOCAL_OPUS_SOURCES := \
$(LOCAL_DIR)/src/opus.c \
...
LOCAL_CFLAGS := -DNONTHREADSAFE_PSEUDOSTACK
LOCAL_C_INCLUDES := \
$(LOCAL_DIR)/include \
$(LOCAL_DIR)/celt \
$(LOCAL_DIR)/silk \
$(LOCAL_DIR)/silk/fixed \
$(LOCAL_DIR)/silk/float
LOCAL_SRC_FILES := $(LOCAL_CELT_SOURCES) \
$(LOCAL_SILK_SOURCES) \
$(LOCAL_SILK_SOURCES_FIXED) \
$(LOCAL_SILK_SOURCES_FLOAT)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_DIR)/include
include $(BUILD_STATIC_LIBRARY)
################
include $(CLEAR_VARS)
LOCAL_MODULE := audio-client-jni
LOCAL_SRC_FILES := audio-client-jni.cpp
# low latency codec
LOCAL_STATIC_LIBRARIES += opus
# for native audio
LOCAL_LDLIBS += -lOpenSLES
# for logging
LOCAL_LDLIBS += -llog
# for native asset manager
LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
为了排除构建作品的方式存在问题,我使用名为 tundra 的不同构建系统完成了完全相同的事情,并且它在使用 MSVC++ 的 Windows 上编译得很好。
这是链接器命令和错误(为了便于阅读,我已经格式化了命令行)
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++
-Wl,-soname,libaudio-client-jni.so
-shared
--sysroot=C:/Projects/android-ndk-r8e/platforms/android-14/arch-arm
C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o
C:/Projects/workspace/AudioClient//obj/local/armeabi/libopus.a
C:/Projects/workspace/AudioClient//obj/local/armeabi/libstdc++.a
-lgcc
-no-canonical-prefixes
-Wl,--no-undefined
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-LC:/Projects/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib
-lOpenSLES
-llog
-landroid
-lstdc++
-lc
-lm
-o C:/Projects/workspace/AudioClient//obj/local/armeabi/libaudio-client-jni.so
错误随之而来
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function (anonymous namespace)::AuClient::ReceiveThenEnqueue():C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:419: error: undefined reference to 'opus_decode'
C:/Projects/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: C:/Projects/workspace/AudioClient//obj/local/armeabi/objs/audio-client-jni/audio-client-jni.o: in function InitializeThread:C:/Projects/workspace/AudioClient//jni/audio-client-jni.cpp:387: error: undefined reference to 'opus_decoder_create'
我需要第二双眼睛,它audio-client-jni.o
之前肯定是链接的,libopus.a
但如果这是我不明白如何修改生成文件以获得预期结果的问题。opus.h API 在包含在 C++ 应用程序中时使用 extern "C" 定义。到目前为止没有运气。