0

这是我完整的 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" 定义。到目前为止没有运气。

4

1 回答 1

0

感谢@AlexCohn 的协助,显然没有任何问题,而是没有正确包含所有源文件,我的部分略有忽略。

就我而言,我不确定应该如何设置才能运行 bin util 命令,幸运的是,它很简单:

"C:\Projects\android-ndk-r8e\toolchains\arm-linux-androideabi-4.6\prebuilt\windows-x86_64\bin\arm-linux-androideabi-nm.exe" "C:\Projects\workspace\AudioClient\obj\local\armeabi\libopus.a"

我只是从预建的工具链中挑选了看起来合理的东西。

通过我的输出,nm我可以验证出口不存在。$(LOCAL_OPUS_SOURCES)仔细检查后,我注意到我忘记将LOCAL_C_INCLUDES. 解决这个问题,解决了这个问题。

于 2013-07-31T09:10:22.323 回答