将库和未定义的引用链接到 JNI 中的函数

Linking library and undefined reference to function in JNI

我试图在我的 JNI 代码中使用两个不同的库:

我尝试使用以下 android.mk 文件编译它们:

TOP_PATH := $(call my-dir)

# Lib native-audio-jni
#------------------------------------------------------------------------------------------------------

APP_PLATFORM := android-19

LOCAL_PATH := $(TOP_PATH)

include $(CLEAR_VARS)

LOCAL_MODULE    := native-audio-jni
LOCAL_SRC_FILES := native-audio-jni.c \ wavfile.c
# for native audio
LOCAL_LDLIBS += -lOpenSLES
# for logging
LOCAL_LDLIBS += -llog
# for native asset manager
LOCAL_LDLIBS += -landroid

include $(BUILD_SHARED_LIBRARY)

#For libsndfile-android
#--------------------------------------------------------------------------------

include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/libsndfile-android

OGG_ROOT := $(LOCAL_PATH)/deps/libogg/include
VORBIS_ROOT := $(LOCAL_PATH)/deps/libvorbis/include

LOCAL_CFLAGS := -DHAVE_EXTERNAL_LIBS
LOCAL_C_INCLUDES := $(OGG_ROOT) $(VORBIS_ROOT)

LOCAL_MODULE   := sndfile

OGG_SRC_FILES := deps/libogg/src/bitwise.c deps/libogg/src/framing.c
V_SRC := deps/libvorbis/src
VORBIS_SRC_FILES := $(V_SRC)/analysis.c $(V_SRC)/floor0.c   $(V_SRC)/lsp.c      $(V_SRC)/res0.c \
       $(V_SRC)/vorbisfile.c $(V_SRC)/bitrate.c $(V_SRC)/floor1.c $(V_SRC)/mapping0.c   $(V_SRC)/sharedbook.c   \
       $(V_SRC)/window.c $(V_SRC)/block.c   $(V_SRC)/info.c   $(V_SRC)/mdct.c   $(V_SRC)/smallft.c \
       $(V_SRC)/codebook.c  $(V_SRC)/lookup.c $(V_SRC)/psy.c  $(V_SRC)/synthesis.c \
       $(V_SRC)/envelope.c  $(V_SRC)/lpc.c  $(V_SRC)/registry.c $(V_SRC)/vorbisenc.c

LOCAL_SRC_FILES := mat5.c windows.c G72x/g723_24.c G72x/g72x.c \
       G72x/g723_40.c G72x/g721.c G72x/g723_16.c \
       float32.c chanmap.c test_endswap.c rf64.c sndfile.c htk.c dither.c \
       test_log_printf.c txw.c ms_adpcm.c ima_adpcm.c flac.c aiff.c \
       wav.c macbinary3.c mat4.c pcm.c caf.c \
       audio_detect.c id3.c alaw.c macos.c file_io.c broadcast.c double64.c \
       raw.c test_broadcast_var.c \
       g72x.c command.c chunk.c avr.c sd2.c voc.c test_audio_detect.c \
       mpc2k.c gsm610.c dwd.c \
       interleave.c common.c test_strncpy_crlf.c sds.c pvf.c paf.c au.c \
       test_float.c \
       vox_adpcm.c ulaw.c strings.c svx.c test_conversions.c rx2.c nist.c \
       GSM610/code.c GSM610/gsm_destroy.c \
       GSM610/gsm_decode.c GSM610/short_term.c GSM610/gsm_create.c \
       GSM610/decode.c GSM610/gsm_option.c \
       GSM610/long_term.c GSM610/table.c GSM610/rpe.c GSM610/preprocess.c \
       GSM610/gsm_encode.c GSM610/lpc.c \
       GSM610/add.c dwvw.c wav_w64.c wve.c ogg.c ogg_vorbis.c w64.c test_file_io.c\
       ircam.c xi.c ima_oki_adpcm.c \
       $(OGG_SRC_FILES) $(VORBIS_SRC_FILES)

LOCAL_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := sndfilelib
LOCAL_STATIC_LIBRARIES := sndfile

include $(BUILD_SHARED_LIBRARY)

当我编译一切正常时,我在各自的体系结构文件夹中得到了我的两个共享库 (.so)。

问题是,当我尝试使用在第二个库(本地静态库)中包含的 .h 文件之一中定义的函数时,出现错误 "undefined reference to function"。

所以我认为应该有一种方法可以 link 这个静态库到非静态库。

我已经尝试将 .h 文件导入到我尝试使用该函数的 .m 文件中,但没有任何变化

请帮助我,感谢您的宝贵时间

尝试将 sndfile 模块的声明移动到文件顶部,然后编辑您的 native-audio-jni 模块添加:

...
LOCAL_SHARED_LIBRARIES := sndfilelib

或者,或者,这个:

...
LOCAL_STATIC_LIBRARIES := sndfile